PHP Curl Save remote server picture
function Loadimagecurl ($save _to) {
$ch = Curl_init ($this->source);
$fp = fopen ($save _to, "WB");
Set URL and other appropriate options
$options = Array (curlopt_file => $fp,
Curlopt_header => 0,
Curlopt_followlocation => 1,
Curlopt_timeout => 60); 1 minute timeout (should be enough)
Curl_setopt_array ($ch, $options);
Curl_exec ($ch);
Curl_close ($ch);
Fclose ($FP);
}
$info = @GetImageSize ($this->source);
$mime = $info [' MIME '];
What sort of image?
$type = substr (STRRCHR ($mime, '/'), 1);
Switch ($type) {
Case ' JPEG ':
$image _create_func = ' imagecreatefromjpeg ';
$image _save_func = ' imagejpeg ';
$new _image_ext = ' jpg ';
Best quality:100
$quality = IsSet ($this->quality)? $this->quality:100;
Break
Case ' PNG ':
$image _create_func = ' imagecreatefrompng ';
$image _save_func = ' imagepng ';
$new _image_ext = ' png ';
Compression Level:from 0 (no Compression) to 9
$quality = IsSet ($this->quality)? $this->quality:0;
Break
Case ' BMP ':
$image _create_func = ' imagecreatefrombmp ';
$image _save_func = ' imagebmp ';
$new _image_ext = ' bmp ';
Break
Case ' gif ':
$image _create_func = ' imagecreatefromgif ';
$image _save_func = ' imagegif ';
$new _image_ext = ' gif ';
Break
Case ' vnd.wap.wbmp ':
$image _create_func = ' imagecreatefromwbmp ';
$image _save_func = ' imagewbmp ';
$new _image_ext = ' bmp ';
Break
Case ' XBM ':
$image _create_func = ' IMAGECREATEFROMXBM ';
$image _save_func = ' IMAGEXBM ';
$new _image_ext = ' XBM ';
Break
Default
$image _create_func = ' imagecreatefromjpeg ';
$image _save_func = ' imagejpeg ';
$new _image_ext = ' jpg ';
}
if (IsSet ($this->set_extension)) {
$ext = STRRCHR ($this->source, ".");
$strlen = strlen ($ext);
$new _name = basename (substr ($this->source, 0,-$strlen)). $new _image_ext;
}else{
$new _name = basename ($this->source);
}
$save _to = $this->save_to. " /blog_insert_temp_ ". Time (). Mt_rand (1,99).". $new _image_ext;
Output object composition is the same as the $_file variable after the same as the normal image upload processing
$img _info[' name '] = basename ($this->source);
$img _info[' type '] = $mime;
$img _info[' size '] = 1000;
$img _info[' tmp_name '] = $save _to;
$img _info[' ERROR '] = 0;
if ($method = = ' Curl ') {
$save _image = $this->loadimagecurl ($save _to);
}elseif ($method = = ' gd ') {
$img = $image _create_func ($this->source);
if (IsSet ($quality)) {
$save _image = $image _save_func ($img, $save _to, $quality);
}else{
$save _image = $image _save_func ($img, $save _to);
}
}
return $img _info;
}