Re: Check if an url is a jpg image
| From: | Richard Davey | Date: | Wed, 12 Oct 2005 10:24:01 +0000 |
| Subject: | Re: Check if an url is a jpg image | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-223949@lists.php.net to get a copy of this message | ||
Hi Tommy,
Wednesday, October 12, 2005, 10:48:55 AM, you wrote:
> Is it possible to check if an url is a jpg image from php?
#1 Quick and unreliable: Check if there is a .jpg or .jpeg as the final
characters of the URL string.
#2 Bit more complex, very expensive: fopen() the URL, download the
content to a temporary location, inspect it with native php functions
like getimagesize. If your PHP config allows, you can probably perform
a getimagesize directly on the URL, but I've not tried this.
#3 Trickier, less expensive than #2, but balls-on accurate: fopen()
the URL (after suitable validation) and grab the header (the first few
KB). JPEG files are easily identified, but come in a variety of
flavours.
http://www.codeproject.com/bitmap/iptc.asp
Cheers,
Rich
--
Zend Certified Engineer
http://www.launchcode.co.uk