Re: Test if picture exists then load.
| From: | Jimmy | Date: | Thu, 10 Jan 2002 15:57:45 +0000 |
| Subject: | Re: Test if picture exists then load. | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-80042@lists.php.net to get a copy of this message | ||
>> Would that be fopen()? or something else? I'm still new to PHP so any
>> feedback would be very appreciated.
> Use file_exists() to check whether a file exists.
file_exists() function is quite slow.
in your case, better do fopen() to check if the file exist,
because you gonna do fopen() anyway if the file exist.
if fopen() return error, then you can assume the file does not exist.
dont forget to add "@" in front of the function name, to surpress err
msg.
if ($f = @fopen($image)) {
// file exist, read the content, then echo to browser
}
else {
// file does not exist, open default image
}
--
Jimmy
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bigamy is having one spouse too many. Monogamy is the same.