FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Images In PHP

 


Ben
Hey,

Does anybody know a way of validating an a URL to check that it is a proper image URL.

So it will pass if for instance http://domain.com/images/image.jpg

But will fail if someone types in http://skjdhfsdhf

Thanks,
Ben Very Happy
comp615
Yeah what you can do is get the address in $var...then assuming you wanted to make sure it was a .jpg you could do:
if(eregi(".jpg"$,$var)) {
echo "Its a jpg";
} else {
echo "thats not a jpg";
die();
}

to include .gif and .png you can replace .jpg with each and use or statements or ||
Ranfaroth
That's wrong.

To check if the resource is an image, you have to parse the HTTP headers, to read the media type.
http://example.org/test.jpg can perfectly be a text file, and http://exmple.org/test.exe can perfeclty be an PNG image Rolling Eyes

So, you have to use fsockopen to connect to the webserver, make your HEAD request, and read the Content-Type answer.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.