|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-04-25 15:57 UTC] soeren dot fleischer at gmx dot net
file_exists("") returns TRUE instead of FALSE.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 16:00:01 2025 UTC |
file_exists("") returns TRUE instead of FALSE As per request, here are more details... This: <? $filename=""; if (is_file($filename)) { print "is_file sais, the file $filename <b>does exist</b>.<br>"; } else { print "is_file sais, the file $filename <b>did not exist</b>.<br>"; } if (file_exists($filename)) { print "file_exists sais, the file $filename <b>does exist</b>.<br>"; } else { print "file_exists sais, the file $filename <b>did not exist</b>.<br>"; } ?> will return: is_file sais, the file did not exist. file_exists sais, the file does exist. Again, in other words: If you give file_exists() an empty string as argument ( file_exists("") ), it will return TRUE (saying the file existed, but it does not, because "" is no file.) is_file() correctly returns FALSE if you give it an empty string as argument and so should file_exists do, as it did in PHP 4.1.2 Further information: I used to check my upload-scripts for uploaded files using $file=$_FILES['datei']['tmp_name']; if (file_exists($file)) { savefile($file); } but I cannot use this anymore because when a user does not upload a file, $filename becomes an empty string and file_exists returns TRUE, so my function savefile($file) wants to save a non-uploaded file.something stinks here: [2002-04-27 10:41:44] sniper@php.net $filename=""; $bb = is_file($filename); var_dump($bb); int(0) yohgaki: $filename=""; $bb = is_file($filename); var_dump($bb); bool(false) so does is_file() return false or 0? plus it returned int(1) for you, which it shouldn't either (should return bool(true) instead). WTF?