php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19503 file_exists() broken for relative paths
Submitted: 2002-09-19 13:41 UTC Modified: 2002-09-19 14:10 UTC
From: nick at nplawes dot com Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 4.2.3 OS: Linux
Private report: No CVE-ID: None
 [2002-09-19 13:41 UTC] nick at nplawes dot com
Hi

I can see many "Closed" versions of this bug report. It definitely is causing me problems, hence this report. I think that Apache 2.0.39 / php 4.2.1 was working, as my code broke after installing Apache 2.0.40 / php 4.2.3.

I always build apache and php with the same options. The server is running as 'nobody'.

is_file() behaves better, although it's not the function I want to use.

A test case... (is_file.php) I would expect is_file and file_exists to give the same results in this test... They don't!

<?php

function lookfor($filename)
{
    $wd = getcwd();
    echo "<b>Looking for '$filename'</b><br>\n";
    $path = "";
    for ($i = 0; $i < 20; $i++)
    {
	$if = is_file($path . $filename) ? 1 : 0;
	clearstatcache();
	$fe = file_exists($path . $filename) ? 1 : 0;
	echo "$if $fe : '$path' ($wd/$filename)<br>\n";
	if ($if) break;
	$path .= "../";
	$wd = dirname($wd);
	if ($wd == "/") $wd = "";
    }
    echo "<br>\n";
}

echo "Starting from '".getcwd()."' (allegedly)<br>\n";
lookfor('System.map');
lookfor('is_file.php');
lookfor('index.php');

?>

Gives:

Starting from '/usr/local/apache2/htdocs/test' (allegedly)
Looking for 'System.map'
0 1 : '' (/usr/local/apache2/htdocs/test/System.map)
0 1 : '../' (/usr/local/apache2/htdocs/System.map)
0 1 : '../../' (/usr/local/apache2/System.map)
0 1 : '../../../' (/usr/local/System.map)
0 1 : '../../../../' (/usr/System.map)
1 1 : '../../../../../' (/System.map)

Looking for 'is_file.php'
1 0 : '' (/usr/local/apache2/htdocs/test/is_file.php)

Looking for 'index.php'
0 0 : '' (/usr/local/apache2/htdocs/test/index.php)
1 0 : '../' (/usr/local/apache2/htdocs/index.php)


Thanks

/nick

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-19 14:10 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 [2002-09-21 16:20 UTC] fil at rezo dot net
I have just installed php 4.2.3 on Mac OS X/Jaguar, and 
file_exists() always returns false ; for the test programme 
sent by Nick, I get


Starting from '/Users/fil/Sites' (allegedly)
Looking for 'System.map'
0 0 : '' (/Users/fil/Sites/System.map)
0 0 : '../' (/Users/fil/System.map)
0 0 : '../../' (/Users/System.map)
0 0 : '../../../' (/System.map)
0 0 : '../../../../' (/System.map)
0 0 : '../../../../../' (/System.map)
0 0 : '../../../../../../' (/System.map)
0 0 : '../../../../../../../' (/System.map)
0 0 : '../../../../../../../../' (/System.map)
0 0 : '../../../../../../../../../' (/System.map)
0 0 : '../../../../../../../../../../' (/System.map)
0 0 : '../../../../../../../../../../../' (/System.map)
0 0 : '../../../../../../../../../../../../' (/System.map)
0 0 : '../../../../../../../../../../../../../' 
(/System.map)
0 0 : '../../../../../../../../../../../../../../' 
(/System.map)
0 0 : '../../../../../../../../../../../../../../../' 
(/System.map)
0 0 : '../../../../../../../../../../../../../../../../' 
(/System.map)
0 0 : '../../../../../../../../../../../../../../../../../' 
(/System.map)
0 0 : 
'../../../../../../../../../../../../../../../../../../' 
(/System.map)
0 0 : 
'../../../../../../../../../../../../../../../../../../../' 
(/System.map)

Looking for 'is_file.php'
0 0 : '' (/Users/fil/Sites/is_file.php)
0 0 : '../' (/Users/fil/is_file.php)
0 0 : '../../' (/Users/is_file.php)
0 0 : '../../../' (/is_file.php)
0 0 : '../../../../' (/is_file.php)
0 0 : '../../../../../' (/is_file.php)
0 0 : '../../../../../../' (/is_file.php)
0 0 : '../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../../../../../' (/is_file.php)
0 0 : '../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : '../../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : '../../../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : '../../../../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : '../../../../../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : 
'../../../../../../../../../../../../../../../../../../' 
(/is_file.php)
0 0 : 
'../../../../../../../../../../../../../../../../../../../' 
(/is_file.php)

Looking for 'index.php'
0 0 : '' (/Users/fil/Sites/index.php)
0 0 : '../' (/Users/fil/index.php)
0 0 : '../../' (/Users/index.php)
0 0 : '../../../' (/index.php)
0 0 : '../../../../' (/index.php)
0 0 : '../../../../../' (/index.php)
0 0 : '../../../../../../' (/index.php)
0 0 : '../../../../../../../' (/index.php)
0 0 : '../../../../../../../../' (/index.php)
0 0 : '../../../../../../../../../' (/index.php)
0 0 : '../../../../../../../../../../' (/index.php)
0 0 : '../../../../../../../../../../../' (/index.php)
0 0 : '../../../../../../../../../../../../' (/index.php)
0 0 : '../../../../../../../../../../../../../' 
(/index.php)
0 0 : '../../../../../../../../../../../../../../' 
(/index.php)
0 0 : '../../../../../../../../../../../../../../../' 
(/index.php)
0 0 : '../../../../../../../../../../../../../../../../' 
(/index.php)
0 0 : '../../../../../../../../../../../../../../../../../' 
(/index.php)
0 0 : 
'../../../../../../../../../../../../../../../../../../' 
(/index.php)
0 0 : 
'../../../../../../../../../../../../../../../../../../../' 
(/index.php)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 16:01:27 2024 UTC