PHP目录名返回符号链接路径 [英] PHP dirname returns symlink path
本文介绍了PHP目录名返回符号链接路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个从'/one/directory/'
到'/two/directory/'
的符号链接.
Say I have a symlink from '/one/directory/'
to '/two/directory/'
.
如果我echo dirname(dirname(\__FILE__))
,它将返回'/one/directory/'
.
返回'/two/directory'
的最佳方法是什么?
What is the best method to return '/two/directory'
?
用法示例:
虚拟主机'example.com'
指向''/two/directory'
Vhost 'example.com'
pointing to `'/two/directory'
example.com/hello_world.php
example.com/hello_world.php
<?php
echo dirname(dirname(__FILE__));
?>
返回: '/one/directory'
预期结果: '/two/directory'
推荐答案
使用readlink
函数吗? http://php.net/manual/zh/function.readlink.php
您可以使用is_link
检查它是否是符号链接: http://php.net/manual/en/function.is-link.php
You can check if it is a symlink with is_link
: http://php.net/manual/en/function.is-link.php
if (is_link($link)) {
echo(readlink($link));
}
这篇关于PHP目录名返回符号链接路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文