PHP Download File from URL using CURL Request Example
Hi Folks,
In this profound tutorial, we will learn php curl download image from url. let’s discuss about php download file from url using curl. if you want to see an example of php save file from url to server then you are in the right place. I explained simply about php save file from url curl. follow the below example for php curl save file to disk.
Whenever you require to download a file or image from a URL using php curl. then you can see that example. we can download images or files from the given URL and save them on 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 the following example :
Example:
index.php
<?php
$url = 'http://www.test.com/1458398816_33370444.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);
fclose($file);
?>
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Curl Request with P12 Certificate Example
- Laravel Http Curl Post Request with Headers Example
- Laravel Http Curl Delete Request Example
- Laravel Http Curl Get Request Example
- PHP Curl Request with Username and Password Example
- PHP Curl Request With Bearer Token Authorization Header Example
- PHP Curl PUT Request Example Code
- PHP Curl Delete Request Example Code
- PHP Curl POST Request with Headers Example
- PHP Curl Get Request with Parameters Example
- PHP Curl Request with Certificate (cert pem file option) Example
- Codeigniter Curl Post Request with Parameters Example
- PHP CURL Post Request with Parameters Example
- Laravel CURL Request Example using Ixudra/curl