Want to download or save any remote images on your server by using simple PHP scripts? In this tutorial I will explain how to download any remoter server images on your server, then keep your close attention in this tutorials as I am going to share “How to Download and Save a Remote Image Using PHP”.
There are three ways to download the remote image which is explained below. See all method and use any one which as per you want.
You can use the simple PHP
copy() function to save any remote images on your server.
file_get_contents() function will copy the remote image and file_put_contents() function will paste it on your destination folder on your server.
$content = file_get_contents('http://example-url.com/images/icon.png');
You can also download the images by using Curl to save the remote image on your server. Use below code in your PHP file.
$ch = curl_init('http://example-url.com/images/icon.png');
$fp = fopen('images/icon.png', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.