How to Download and save image on your server using PHP

JavaScript Array, search value increase PHP Execution Time connect multiple database display source code save image Export MySQL Database configure mongodb send email from localhost

How to Download and save image on your server using PHP. Now Download image using php code. Store image in Folder using this php Question. 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.

Also Read : Export mysql Database using php

Here is method for Download and save image on your server using PHP

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

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

Method-2: 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: 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);

Leave a Reply