note 72484 deleted from function.is-file by nlopess
| From: | nlopess@php.net | Date: | Sun, 21 Jan 2007 15:53:37 +0000 |
| Subject: | note 72484 deleted from function.is-file by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-122002@lists.php.net to get a copy of this message | ||
Note Submitter: gouttonio at gmail dot com
----
I just noticed that you should always test a path with is_file() before pouring it in
getimagesize(), because even with the '@', getimagesize will return a fatal error on some
servers (I work on french servers).
so :
<?
// Don't
$avatar = '';
if ($size = @getimagesize($_SERVER['DOCUMENT_ROOT'].'/'.$maybewrongimagepath))
$avatar = '<img src="'.$maybewrongimagepath.'" '.$size[3].'
alt="" />';
// Will return an error (notice the "@")
// Use
$avatar = '';
if (is_file($_SERVER['DOCUMENT_ROOT'].'/'.$maybewrongimagepath))
{
if ($size = @getimagesize($_SERVER['DOCUMENT_ROOT'].'/'.$maybewrongimagepath))
$avatar = '<img src="'.$maybewrongimagepath.'" '.$size[3].'
alt="" />';
}
?>
Hoping this'll help...