How to Download File from URL in PHP
Hello developer, in this tutorial i am going to show you that php curl download file from remote server. If you don't know how to do it, then you are a right plcae. This tutorial is for you.
Though you can do it using get_file_contents() in php but i think it is better to use php cURL. So let' see how we can dot php curl save file from url.
$url = 'http://www.example.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 it can help you.