FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Failed @getimagesize() print to error_log?
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Failed @getimagesize() print to error_log? [message #173076 is a reply to message #173066] Sun, 20 March 2011 17:24 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Sat, 19 Mar 2011 18:58:24 -0700, jwcarlton wrote:

> I have the following in a script:
>
> if (($image) && (@getimagesize("/home/myaccount/www/thumbs/$image")))
> $height = "75";
>
> else {
> $image = "noimage.gif";
> $height = "75";
> }

> And I have a gazillion of these in my error log:

Tell me, are you taking user input in some form and expecting it to match
the name of a thumbnail file on the server?

If so, what controls are you placing on that user input to ensure that a
valid file name is requested?

Note that the *only* validation that you can rely on is validation
carried out by the server after the request is received from the viewers
browser.

Maybe:

<?php
if (is_set($image) && $image) {
$imgFileName = "/home/myaccount/www/thumbs/$image";
if (file_exists($imgFileName)) {
if (getimagesize($imgFileName)) {
// nothing to do here
else {
$image = "noimage.gif"; // file exists but not an image
}
} else {
$image = "noimage.gif"; // file doesn't exist
}
} else {
$image = "noimage.gif"; // $image was not defined or was false
}
$height = "75"; // always do this
?>

would better meet your needs?

However, from the manual:

"If accessing the filename image is impossible, or if it isn't a valid
picture, getimagesize() will generate an error of level E_WARNING. On
read error, getimagesize() will generate an error of level E_NOTICE."

So using getimagesize to determine if it really is an image will always
generate a warning message if it's not an image file. This means that the
above code will only prevent any "file doesn't exist" related warnings,
and not "file isn't an image" related warnings.

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PDO MySQL
Next Topic: Very strange behaviour of imageftbbox()?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 10:46:22 GMT 2024

Total time taken to generate the page: 0.05106 seconds