PHP download file from url using curl example

By Hardik Savani | March 21, 2016 | Category : PHP CURL

Whenever you require to download file or image from URL using php curl. then you can see that example. we can download image or file from given url and save in over local server. you can do that using get_file_contents() in php too, but i think it is good if you are doing that using PHP curl. let's see following example :


$url = '';

$curlCh = curl_init();

curl_setopt($curlCh, CURLOPT_URL, $url);

curl_setopt($curlCh, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curlCh, CURLOPT_SSLVERSION,3);

$curlData = curl_exec ($curlCh);

curl_close ($curlCh);

$downloadPath = "upload/flower10.jpg";

$file = fopen($downloadPath, "w+");

fputs($file, $curlData);


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.