Req #48548 [Opn->Nab]: file_exists() returns false on paths using ../ in middle
Edit report at https://bugs.php.net/bug.php?id=48548&edit=1
ID: 48548
Updated by: danack@php.net
Reported by: adam at e-nition dot com
Summary: file_exists() returns false on paths using ../ in
middle
-Status: Open
+Status: Not a bug
Type: Feature/Change Request
Package: Filesystem function related
Operating System: Linux
PHP Version: 5.2.9
Block user comment: N
Private report: N
New Comment:
There does not appear to be a bug here. The behaviour is correct for the reported case....and I
don't think breaking it on Windows would be appreciated.
Previous Comments:
------------------------------------------------------------------------
[2009-06-16 13:39:25] adam at e-nition dot com
I fully understand that as I have tried it, but the include and require functions manage this
correctly? Seems a bit silly to be able to include a file with this type of path but not check if it
exists?
Also, if this were to work this way both windows and linux setups would match - which is always nice
:)
Either way thanks for looking at it.
Adam
------------------------------------------------------------------------
[2009-06-16 13:33:53] ben at nurfuerspam dot de
This is actually not a bug, as the path cannot be traversed on a filesystem either.
Just try it in any *nix shell for yourself:
When you call "cd fake_dir/../" you'd expect to cut off the fakepath and stay in the
same directory, but you'll get a "No such file or directory" error instead as there
is no fake_dir that could be resolved.
------------------------------------------------------------------------
[2009-06-14 16:23:50] adam at e-nition dot com
Description:
------------
The file_exists() function returns false on files that do exist but use a directory traversal in the
path. Not at the start of the path, I mean in the middle of the path. (This type of path works fine
on the include function)
Works fine on windows apache2.2.11 php5.2.9
Reproduce code:
---------------
(Example based on a file called 'real_file.php' being placed in a directory called
'real_dir')
$test_path = 'real_dir/fake_dir/../real_file.php',
if (file_exists($test_path)) {
echo 'File does exist<br />';
echo (@include($test_path)) ? 'File included' : 'File NOT included';
} else {
echo 'File does Not exist<br />';
echo (@include($test_path)) ? 'File included' : 'File NOT included';
}
Expected result:
----------------
File does exist
File included
Actual result:
--------------
File does NOT exist
File included
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=48548&edit=1
Thread (4 messages)