FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free 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.
Related topics
Great php editor
[tutor] How to protect images without htaccess using PHP
What do you use to make your page layout?
Dynamic PHP Images
Includ Images using PHP.
Uplaoding images using php form :::: Help needed
Image Position
CSS for making images go through a php code.
Whats the best PHP 5 editor?
PHP and captions
PHP question about passing variables (noob)
May I ask to enable or load the apache module
IE8 not allowing new random image on each page (PHP and CSS)
Need help with watermarks
PHP-Fusion | An Open Source CMS | PHP & MySQL Based
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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