/    Sign up×
Community /Pin to ProfileBookmark

How would I go about downloading an image to a directory.

I’m trying to figure out how I would go about directly downloading an image with php and having it saved in a directory on the server.

I know that I can retrieve the url for the image with cURL but can the image itself be retrieved with cURL. What would be the easiest route to download an image directly to the server.

Any help would be greatly appreciated!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeOct 01.2008 — try this
[code=php]$image_url = "http://127.0.0.1/image.jpg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $image_url);
$result = curl_exec($ch);
file_put_contents("downloaded_image.jpg",$result);[/code]


Scott.
×

Success!

Help @Newyork_Rules 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...