paatrick

saveImage

Jan 27th, 2021
602
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   function saveImage($path) {
  2.  
  3.     if(!preg_match('/\/([^\/]+\.[a-z]{3,4})$/i', $path, $matches)) die('Use image please');
  4.  
  5.     $image_name = strToLower($matches[1]);
  6.     $ch = curl_init($path);
  7.  
  8.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.     curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  10.  
  11.     $img = curl_exec ($ch);
  12.     curl_close ($ch);
  13.  
  14.     $fp = fopen($image_name,'w');
  15.     fwrite($fp, $img);
  16.     fclose($fp);
  17.   }
RAW Paste Data