Say I have a symlink from '/one/directory/'
to '/two/directory/'
.
If I echo dirname(dirname(\__FILE__))
, it returns '/one/directory/'
.
What is the best method to return '/two/directory'
?
Example usage:
Vhost 'example.com'
pointing to `'/two/directory'
example.com/hello_world.php
<?php echo dirname(dirname(__FILE__)); ?>
Returns: '/one/directory'
Expected results: '/two/directory'
Use readlink($path) to read the target of symbolic link.
Use the
readlink
function? http://php.net/manual/en/function.readlink.phpYou can check if it is a symlink with
is_link
: http://php.net/manual/en/function.is-link.phpDocumentation:
http://php.net/manual/en/function.is-link.php
http://php.net/manual/en/function.readlink.php
Maybe with realpath() ? http://php.net/manual/en/function.realpath.php
Edit : readlink seems to be a better answer :)
Use the https://github.com/logical-and/symlink-detective and
will return
'/two/directory'