How to get canonicalized path (realpath) of nonexistent file in PHP?
script.php $filename = realpath(sprintf("%s/%s", getcwd(), $argv[1])); var_dump($filename); Let's try some things [/foo/bar/bof] $ php script.php ../foo.txt string(16) "/foo/bar/foo.txt" [/foo/bar/bof] $ php script.php ../nonexistent.txt bool(false) Dammit! realpath is returning false because the file doesn't exist. What I'd like to see for the ../nonexistent.txt is string(24) "/foo/bar/nonexistent.txt" How can I get the canonicalized path for any relative path in PHP? Note: I saw some questions regarding resolving symlink paths. Answers to these questions are not applicable to my question.
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.