Added realpath to dirname usages

This should solve every issue which might happen as described in #750. By first calculating the real path (see http://www.php.net/manual/en/function.realpath.php) the dirname function should always return the parent dir (and not just remove the last `../`). 

#750 can be closed after merge.