Home php PHP download file from url by using curl example

PHP download file from url by using curl example

by Shahriar Sagor

Today now in this post i will show you how to download file from url by using curl. Whenever we have need to download any file or image from URL by using php curl. Then we can see that example. we can download image or aby file from given url and we can save in over local server. We can do that by using get_file_contents() in php too, but i think it is good if we are doing that by using PHP curl.

So let’s start and see following example :


$url = 'http://www.codingspoint.com/398816893_13433370444.jpg';

$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);

Read Also : How to Create Custom Blade Directive in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook.


You may also like