[PHP] Test if picture exists then load.

2002-01-10 Thread Dean Householder

I'm not sure what function I need to use, but I want to test if a picture exists in a 
directory and if it does to display it but if not display another graphic that says 
'No Graphic Available'.  

Would that be fopen()?  or something else?  I'm still new to PHP so any feedback would 
be very appreciated.

Dean



Re: [PHP] Test if picture exists then load.

2002-01-10 Thread Jason Wong

On Thursday 10 January 2002 18:19, Dean Householder wrote:
 I'm not sure what function I need to use, but I want to test if a picture
 exists in a directory and if it does to display it but if not display
 another graphic that says 'No Graphic Available'.

 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.

To check whether is is a valid image file you could use getimagesize().

hth
-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
Military justice is to justice what military music is to music.
-- Groucho Marx
*/

-- 
PHP General 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]




Re: [PHP] Test if picture exists then load.

2002-01-10 Thread Jimmy

 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.



-- 
PHP General 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]