note 39136 added to function.file-exists
| From: | frankboumphrey at rn2 dot php dot net | Date: | Sun, 18 Jan 2004 15:04:22 +0000 |
| Subject: | note 39136 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63777@lists.php.net to get a copy of this message | ||
file_exists can decieve you sometimes.
if you are building a path from a database, say an image path you may have some thing like this
$filename="banners/".$arr[0];
where $arr[0] is the file name derived from the database
now before displaying the image you want to make sure that it is in fact in the directory thus:
if(file_exists($filename))
echo "<img src='$filename' border='0' />"
Unfortunately this will display if $arr[0] is empty or null because "banners/" does in
fact exist!
therefore it is better to use is_file
if(is_file($filename))
echo "<img src='$filename' border='0' />"
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39136
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39136&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39136&report=yes
Search -- http://master.php.net/manage/user-notes.php