Why would this string be returning false in PHP when realpath()'d?

放肆的年华 提交于 2019-12-11 05:02:32

问题


Here is my string

$newPath = '/~new/assets/js/../packages/prettyphoto/js/jquery.prettyPhoto.js';

Now check this output

var_dump($newPath); // string(64) "/~new/assets/js/../packages/prettyphoto/js/jquery.prettyPhoto.js"
var_dump(realpath($newPath)); // bool(false)

Does anyone know why this would be returning false on me?


回答1:


Hey, you were the guy who provided the manual link in your last question! Don't just link it, read it. :)

realpath() returns FALSE on failure, e.g. if the file does not exist.




回答2:


You can find out by adding

print_r(error_get_last());

After your statement. The possible errors are described in the man page.




回答3:


A quick look on the php.net definition of realpath shows this note, which may be pertinent:

Note: The running script must have executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE.



来源:https://stackoverflow.com/questions/2338935/why-would-this-string-be-returning-false-in-php-when-realpathd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!