Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- gd: imagecreatefrom how to check
March 13, 2007, 9:02 am
rate this thread
Re: gd: imagecreatefrom how to check
Open the file using fopen() and read in the first 10 bytes. Now close the
file. Match the first ten bytes using the following:
$is_image_png = preg_match('/^.PNG/', $ten_bytes);
$is_image_jpeg = preg_match('/(Exif|JFIF)$/', $ten_bytes);
Note, it's also fairly easy to check for a few other common file types:
$is_image_gif = preg_match('/^GIF8/', $ten_bytes);
$is_audio_ogg = preg_match('/^Ogg/', $ten_bytes);
$is_script = preg_match('/^#!\//', $ten_bytes);
Of course, it's not a rigid test that the file really is of that type, but
it's a nice quick check, and should help you differentiate between JPEG
and PNG images fairly easily.
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
- » ssh on command line: force using a group size (prime size) of 1024 (and no...
- — The site's Newest Thread. Posted in » Secure Shell Forum