Reputation: 463
I have to copy JPG from an external server, such as Facebook, to my server.
What is the best way to do so? I though maybe with fread
/fopen
etc. but I don't know if it is the best way.
Upvotes: 1
Views: 3942
Reputation: 16563
You can use URLs with most filesystem functions (like copy
).
$url = "http://cdn.sstatic.net/stackoverflow/img/sprites.png";
$target = "/tmp/stackoverflow.png";
copy($url, $target);
Do note that you need to have the php.ini setting allow_url_fopen
enabled.
Upvotes: 3
Reputation: 6909
$url = 'http://facebook.com/image.jpg';
$img = '/my/folder/image.jpg';
file_put_contents($img, file_get_contents($url));
Upvotes: 1