Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save remote img-file to server, with php

Tags:

php

save

I want to save a remote img-file to my server, but I don't know how to do.

The image url is http://img.youtube.com/vi/Rz8KW4Tveps/1.jpg and 1.jpg is to be saved and renamed to imgfolder/imgID.jpg

like image 962
Johan Avatar asked Sep 03 '09 07:09

Johan


1 Answers

You can use file_get_contents() to load the remote image to a binary string inside your PHP script (file access in PHP often accepts URLs to access remote resources - this is very handy), then store that file somewhere where you have write access. Here is a very simple example:

$image = file_get_contents("http://img.youtube.com/vi/Rz8KW4Tveps/1.jpg");
file_put_contents("imgfolder/imgID.jpg", $image);

Tada!

like image 163
Guss Avatar answered Sep 29 '22 11:09

Guss