How to save Image from URL to local disc in PHP

2 Answers

0 votes
$url = 'http://coupondiscountblog.com/images/dreamcloudsleep-mattress.jpg';

$path = 'd:\img.png';

file_put_contents($path, file_get_contents($url));

echo "Done.";


/*
run:
  
Done.
     
*/

 



answered Sep 19, 2019 by avibootz
0 votes
$url = 'http://coupondiscountblog.com/images/dreamcloudsleep-mattress.jpg';

$path = 'd:\img.png';

$cu = curl_init($url);
$fp = fopen($path, 'wb');
curl_setopt($cu, CURLOPT_FILE, $fp);
curl_setopt($cu, CURLOPT_HEADER, 0);
curl_exec($cu);
curl_close($cu);
fclose($fp);

echo "Done.";


/*
run:
  
Done.
     
*/

 



answered Sep 19, 2019 by avibootz
...