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

Home » Imported messages » comp.lang.php » Checking if file is an image
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Checking if file is an image [message #170863 is a reply to message #170857] Sat, 04 December 2010 03:34 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 12/3/2010 8:37 PM, jwcarlton wrote:
> I have a section that shows an uploaded image. I was doing this:
>
> list($width, $height, $type, $attr) = @getimagesize("/path/to/
> $image");
>
> if (!$width) {
> $image = "noimage.gif";
> $width = "75";
> $height = "95";
> }
>
> I understand that error suppression has a bit of a performance hit,
> though, so I'm curious if either of these would be better:
>
> if (is_readable("/path/to/$image"))
> list($width, $height, $type, $attr) = @getimagesize("/path/to/
> $image");
>
> if (getimagesize("/path/to/$image"))
> list($width, $height, $type, $attr) = @getimagesize("/path/to/
> $image");
>
>
> Either would still be followed with "if (!$width)...". I know that
> neither are fool-proof because they don't check that someone didn't
> rename an .xls or .exe to .jpg, but I can probably control that better
> on the upload side than checking here on every page load. Here, I'm
> more concerned with speed, and not showing any error messages for
> faulty images.
>
> TIA,
>
> Jason

You're prematurely optimizing (again). Unless you're getting 10K
hits/second on your server, you won't notice the difference.

Write your code in a way that is understandable and maintainable. Once
you get the site up (and ONLY then), see if you have a performance
problem. If you do (there's 99.99% chance you won't), find the cause of
the problem and fix it.

But right now you're spending a lot of time worrying about something
that almost assuredly won't be a problem.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Efficiency of a lot of variables
Next Topic: web solutions for global presence
Goto Forum:
  

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

Current Time: Wed Nov 27 00:40:29 GMT 2024

Total time taken to generate the page: 0.04222 seconds