PHP download file from url using curl example

PHP download file from url using curl example

In this post we will give you information about PHP download file from url using curl example. Hear we will give you detail about PHP download file from url using curl exampleAnd how to use it also give you demo for it if it is necessary.

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 :

Example

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

Hope this code and post will helped you for implement PHP download file from url using curl example. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

5  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US