I apologize - I also could not reproduce the bug in the simple test script I previously submitted - I was sure that that would reproduce it. But it did not match exactly what was going on in my actual script. The problem seems to only occur when two file_exists statements are used in a row and the path argument used uses the same "slash style" each time. See the attached script - it is commented so you can see the problem and it should work - I have tested this one. Thanks. At 07:07 AM 7/11/01 +0000, you wrote: >ID: 12033 >Updated by: zak >Reported By: [EMAIL PROTECTED] >Old Summary: file_exists doesn't work properly with variables >Status: Open >Bug Type: Any >Operating System: Win 95 >PHP Version: 4.0.5 >New Comment: > >I cannot reproduce this under Windows 2000 with PHP 4.0.6 > >Do you get the same error if you use a literal value instead of a variable. > >ie. >var_dump (file_exists ("c:/some_random_file_name")); >or >var_dump (file_exists ("c:\\some_random_file_name")); > >Previous Comments: >------------------------------------------------------------------------ > >[2001-07-11 01:00:59] [EMAIL PROTECTED] > >The following won't work in Win95: > >$path="c:/test.bat"; >if(file_exists($path)) {print "file $path exists"} > >This will report a file existing even though it doesn't. You might think >that this is because we are using forwardslashes in windows BUT IF you >then parse $path to replace the forwardslashes with backslashes (using a >regular expression) it still doesn't work. BUT if you do this: >$path="\"".$path."\""; >(leaving $path with forward slashes) it does work properly. > >I suppose this is a bug? > >------------------------------------------------------------------------ > > > >ATTENTION! Do NOT reply to this email! >To reply, use the web interface found at http://bugs.php.net/?id=12033&edit=1
<?php /*This is an example of an apparent bug using file_exists twice (tested on a win95 system using php 4.0.4 cgi version, omnihttpd). The second test of file_exists will report a false positive (that the file does exist when it doesn't) unless you use a unix style path as an argument to the first test, and a dos style as an argument to the second test, or vice-versa, i.e, you will get a false positive on the second statement if you use the same path style both times even though the first file_exist statement will evaluate properly.Also see comments below. */ $ms_windows=true; echo "<html><body>\r\n"; //create test file $file_name="c:\\test\\test_file_exist.txt"; exec("dir > $file_name"); echo "File $file_name created<br>"; $file_name_unix="c:/test/test_file_exist.txt"; $file_name_dos="c:\\test\\test_file_exist.txt"; /******First File_Exist Test ******* This will always evaluate properly but the style of the argument used effects whether the second file_exist test below works." ************************************/ //if(file_exists($file_name_unix)){ if(file_exists($file_name_dos)){ deleteFile($file_name); echo "File $file_name deleted"; } else { echo "Can't find $file_name - not deleting<br>"; } /*****Second File_Exist Test ************************ The file_exist statement below won't evaluate properly (giving a false positive) unless you use unix style file name first, then dos style second, or dos style first, and unix style second. Can't use them at same time - otherwise this second file_exist test will report that the file does exist when it doesn't exist. Test this for yourself by alternating the commented if statements in the first and second file exist tests. The script as written will produce a false positive that the file does exist. ******************************************************/ //if(file_exists($file_name_unix)){ if(file_exists($file_name_dos)){ //To fix, comment out this line, and remove the // on the above line OR you can do the same for the first file_exist test above echo "<br>File $file_name exists<br>"; } else { echo "<br>File $file_name does not exist<br>"; } function deleteFile($file_name) { global $ms_windows; if($ms_windows) { // $file_name=formatPath($file_name); exec("del $file_name"); } else { unlink($file_name); } } ?>
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]