How to save picture from url if it has no extension?
How to save picture from url if it has no extension by using php of course.
I use curl for save images (I need a extension of that files), but there is some sort of image that I can't save, the problem in it's url's: like that: http://url.com/image.jpg?blablabla and etc. What I must do with that images if I want to download it?
The server SHOULD respond to your request with a mime-type/content-type header.
Extensions are not really important, from what I understand they only serve two purposes:
$ch = curl_init("http://url.com/image.jpg?blablabla");
$info = curl_getinfo($ch);
curl_close($ch); // always close handle
1) to help end-users identify types of files without having to open them
2) for operating systems to add some type of image/logo and default program associated with an extension.
They carry absolutely zero weight as far as the file's actual contents go. The only reason your .php files are executed using PHP is because there is an apache directive more or less like this:
You can rename all of your php files jpg and add this directive:
AddHandler x-httpd-php5.3 .php
AddHandler x-httpd-php5.3 .jpg
I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;
You could also try loading it into getimagesize(), and see what it finds. It returns an array, with element "2" being a PHP constant for the image type, and element 'mime' being the MIME type (or the function returns Boolean false if it does not recognize it as a known image type).
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread