Skip to content

Instantly share code, notes, and snippets.

@thiagosf
Created January 25, 2012 19:08
Show Gist options
  • Save thiagosf/1677958 to your computer and use it in GitHub Desktop.
Save thiagosf/1677958 to your computer and use it in GitHub Desktop.
Download de imagem externa
<?php
function _downloadImage ($url, $fullpath = 'local/path/')
{
$pathinfo = pathinfo($url);
$fullpath = $fullpath . $pathinfo['basename'];
$out = $fullpath;
$ch = curl_init($url);
$fp = fopen($fullpath, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return $out;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment