php fileexists 路径,php – file_exists和包含相对路径的路径(“/../”)

博客探讨了在PHP安全模式下,file_get_contents与file_exists函数处理路径的不同。当尝试访问安全模式认为不安全的文件时,file_exists会因为查找丢失的目录而失败,而file_get_contents仍能读取文件内容。这揭示了两者在解析路径时的内在差异。
摘要由CSDN通过智能技术生成

听起来你打开了安全模式并试图访问PHP在安全模式下运行时认为不安全的文件.

From the manual:

Warning

This function returns FALSE for files inaccessible due to safe mode restrictions. However these files still can be included if they are located in safe_mode_include_dir.

编辑:如果/ a / path / to / a /不是真实路径,您也可以重现此行为.例如:

$dir1 = '/realDir/realDir2/filetoinclude.php';

echo "File content dir1:\n";

echo file_get_contents($dir1); // outputs file contents

echo "\ndir1 exists: ".(int)file_exists($dir1); // outputs 1

$dir2 = '/realDir/realDir2/realDir3/../filetoinclude.php';

echo "\n\nFile content dir2:\n";

echo file_get_contents($dir2); // outputs file contents

echo "\ndir2 exists: ".(int)file_exists($dir2); // outputs 1

$dir3 = '/realDir/realDir2/NotARealDirectory/../filetoinclude.php';

echo "\n\nFile content dir3:\n";

echo file_get_contents($dir3); // outputs file contents

echo "\ndir3 exists: ".(int)file_exists($dir3); // outputs 0

这是因为file_exists需要遍历整个路径,因此它会查找丢失的目录并失败.我不确定file_get_contents到底有什么不同,我在谷歌上找不到多少,但它显然对路径的解析与file_exists的做法不同.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值