// get a remote image and save it
// $path example: '/home/www/images/myimage.jpg'
$remote_img = 'http://www.somwhere.com/images/image.jpg';
$img = imagecreatefromjpeg($remote_img);
$path = 'images/';
imagejpeg($img, $path);
// Alternative Image Saving Using cURL - useful if
// the allow_url_fopen function is disabled.
// $fullpathexample: '/home/www/images/myimage.jpg'
FUNCTION save_image($img, $fullpath){
$ch = curl_init ($img);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec($ch);
curl_close ($ch);
IF(FILE_EXISTS($fullpath)){
UNLINK($fullpath);
}
$fp = FOPEN($fullpath,'x');
FWRITE($fp, $rawdata);
FCLOSE($fp);
}