Image Validation
Posted: Sun Apr 22, 2007 10:17 pm
So in all this time that I've been missing from the forums, I've been developing a few websites. Gets a little busy when it starts to warm up. Anyway, I've been playing around with the GD library a bit more and this time, I decided not to use any tutorials. NOW it makes sense. PHP manual is the greatest. 
But I've got a problem. I've been doing a lot of testing and purposely hacking my site to pieces, finding and fixing little bugs, and I've ran into one that bothers me.
When uploading a corrupt JPEG, I get a warning from imagecreatefromjpeg(). According to GD lib, it's an "unrecoverable error." It's only a warning and doesn't affect my scripts in any way, and it'll disappear when I go live and turn off printed error_reporting, but I've just got to know... Can I validate images?
Image validation gives me an error on corrupt files and when refreshing the page with an upload request, I get a "Read error!" warning from getimagesize().
I use $_FILES validation, file_exists($_FILES['foo']['tmp_name']), and getimagesize() which was, hopefully, going to be my last step of validation. It works, but throws a warning. Is there a way to find the error BEFORE throwing it into functions that like to throw warnings?
I've been going through the manual all day and can't seem to find the function I'm after. exif stuff seemed a little promising, but I haven't set it up on my server yet. I figured I'd put my pride aside for a second and ask.
But I've got a problem. I've been doing a lot of testing and purposely hacking my site to pieces, finding and fixing little bugs, and I've ran into one that bothers me.
When uploading a corrupt JPEG, I get a warning from imagecreatefromjpeg(). According to GD lib, it's an "unrecoverable error." It's only a warning and doesn't affect my scripts in any way, and it'll disappear when I go live and turn off printed error_reporting, but I've just got to know... Can I validate images?
Image validation gives me an error on corrupt files and when refreshing the page with an upload request, I get a "Read error!" warning from getimagesize().
I use $_FILES validation, file_exists($_FILES['foo']['tmp_name']), and getimagesize() which was, hopefully, going to be my last step of validation. It works, but throws a warning. Is there a way to find the error BEFORE throwing it into functions that like to throw warnings?
I've been going through the manual all day and can't seem to find the function I'm after. exif stuff seemed a little promising, but I haven't set it up on my server yet. I figured I'd put my pride aside for a second and ask.