Download image from URL and Save into Folder in PHP CURL

Download image from URL and Save into Folder in PHP CURL

If you want to download the image from an URL in PHP application so you can use PHP CURL to handle that. With CURL you can download an image and store into a directory or a particular location. Also, you can use get_file_contents() for doing the same thing. but I can suggest using PHP curl to handle that.

Before this make sure your upload directory has proper permissions also to check your php.ini file for allow_url_fopen is on.

Here I am just giving you a quick example of PHP CURL.





$url = 'https://i2.wp.com/www.technologyshouters.com/wp-content/uploads/2018/01/Laravel-5.5-import-export-to-excel-and-CSV-using-maatwebsite-example..png';


$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 = "images/demo.jpg";
$file = fopen($downloadPath, "w+");
fputs($file, $curlData);
fclose($file);




Krishna Gupta

Krishna Ballabh Gupta is a Gold Medalist Full Stack Developer & Algorithm Designer and Founder of TechnologyShouters. He generally Blogs about Python, JavaScript, jQuery, AngularJS, Database, PHP, AJAX and something that interesting.

Related Posts

Create Account



Log In Your Account



1Subscribe to Our Live Updates.