You are here: Re: gd: imagecreatefrom how to check « PHP Programming Language « IT news, forums, messages
Re: gd: imagecreatefrom how to check

Posted by Toby A Inkster on 03/13/07 10:05

avlee wrote:

> i need to check if the file is png or jpeg.
> How can i do it ?

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[79]/', $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!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация