/    Sign up×
Community /Pin to ProfileBookmark

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: [url]http://url.com/image.jpg?blablabla[/url] and etc. What I must do with that images if I want to download it?
Thank you.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Jun 18.2011 — [CODE]http://url.com/image.jpg?blablabla[/CODE]

[U]The server [U]SHOULD[/U] respond to your request with a mime-type/content-type header. [/U]

[code=php]<?php

$ch = curl_init("http://url.com/image.jpg?blablabla");
curl_exec($ch);
$info = curl_getinfo($ch);
echo $info["CURLINFO_CONTENT_TYPE"];
curl_close($ch); // always close handle

?>[/code]


Extensions are not really important, from what I understand they only serve two purposes:

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:

[CODE]
<FilesMatch ".php$">
AddHandler x-httpd-php5.3 .php
</FilesMatch>
[/CODE]


You can rename all of your php files jpg and add this directive:

[CODE]
<FilesMatch ".jpg$">
AddHandler x-httpd-php5.3 .jpg
</FilesMatch>
[/CODE]


?

Cheers
Copy linkTweet thisAlerts:
@NogDogJun 18.2011 — 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).
×

Success!

Help @ijs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...