Download and save a remote image on your server using PHP

In this tutorial I am going to show you some PHP Methods By which you can easily download remote server image on your local server. Suppose you don’t have FTP access of images but you are able to access images via http port and you want to perform bulk image download then these methods are very useful and you can try any of them to download and save a remote images on your server folder.
download-remote-image

Method-1: By using simple copy() function in PHP

copy("http://example.com/profile.jpg", 'images/profile.jpg');



Method-2: By using simple file_get_contents() & file_put_contents() function in PHP

$content = file_get_contents('http://example.com/profile.jpg');
file_put_contents('images/profile.jpg', $content);



Method-3: By using simple CURL methods in PHP

$ch = curl_init('http://example.com/profile.jpg');
$fp = fopen('images/profile.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);



Posted in PHP