Save Any Website Image to your Server


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. function saveImage($path) {
  4.  
  5. if ( !preg_match('/\/([^\/]+\.[a-z]{3,4})$/i', $path, $matches) ) die('Use image please');
  6.  
  7. $image_name = strToLower($matches[1]);
  8.  
  9. $ch = curl_init ($path);
  10. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  11. curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
  12.  
  13. $img = curl_exec ($ch);
  14. curl_close ($ch);
  15.  
  16. $fp = fopen($image_name,'w');
  17. fwrite($fp, $img);
  18. fclose($fp);
  19.  
  20. }
  21.  
  22. saveImage('http://nettuts.s3.cdn.plus.org/513_jsFromNull/javascript-from-null.jpg');
  23.  
  24. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.