PHP Detecting if source image url link leads to a “broken” image?

Deathbywar

New Member
Suppose you have a thumbnail generator script that accepts source images in the form of a URL. Is there a way to detect if the source URL is "broken" - whether nonexistent or leads to an non-image file? Just brute force using \[code\]getimagesize()\[/code\] or another PHP GD function is not a solution, since spoofed stray URL's that might not be images at all (\[code\]http://example.com/malicious.exe\[/code\] or the same file, but renamed as \[code\]http://example.com/malicious.jpg\[/code\]) could be input - such cases could easily be detected by PHP before having to invoke GD. I'm looking for GD pre-sanitizing before having GD try its battalion at parsing the file.as a first step, the following regular expression checks if the URL is an image extension: \[code\]preg_match('@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)([^\s]+(\.(?i)(jpg|png|gif|bmp))$)@', $txt,$url);\[/code\]
 
Back
Top