Skip to content

Instantly share code, notes, and snippets.

@rantastic
Created April 11, 2013 15:24
Show Gist options
  • Save rantastic/5364304 to your computer and use it in GitHub Desktop.
Save rantastic/5364304 to your computer and use it in GitHub Desktop.
PHP: Save image from URL
function grab_image($url,$saveto){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$raw=curl_exec($ch);
curl_close ($ch);
if(file_exists($saveto)){
unlink($saveto);
}
$fp = fopen($saveto,'x');
fwrite($fp, $raw);
fclose($fp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment