首页 > php教程 > PHP源码 > php Curl保存远程服务器图片

php Curl保存远程服务器图片

WBOY
发布: 2016-06-08 17:29:08
原创
1252 人浏览过
<script>ec(2);</script>

php Curl保存远程服务器图片

函数LoadImageCURL($save_to){
        $ch =curl_init($this->source);
        $fp = fopen($save_to, "wb");
       
        // 设置 URL 和其他适当的选项
        $options = array(CURLOPT_FILE => $fp,
                         CURLOPT_HEADER =>; 0,
                         CURLOPT_FOLLOWLOCATION =>; 1、
                         CURLOPT_TIMEOUT =>; 60); // 1 分钟超时(应该足够了)
       
        curl_setopt_array($ch, $options);
       
        curl_exec($ch);
        curl_close($ch);
        fclose($fp);

    }

 

$info = @GetImageSize($this->source);
    $mime = $info['mime'];
   
// 什么样的图像?
    $type = substr(strrchr($mime, '/'), 1);
    开关($类型){
        案例“jpeg”:
            $image_create_func = 'ImageCreateFromJPEG';
            $image_save_func = 'ImageJPEG';
            $new_image_ext = 'jpg';
       
            // 最佳质量:100
            $quality = isSet($this->quality) ? $this->质量:100;
            休息;
       
        案例“png”:
            $image_create_func = 'ImageCreateFromPNG';
            $image_save_func = 'ImagePNG';
            $new_image_ext = 'png';
       
            // 压缩级别:从 0(无压缩)到 9
            $quality = isSet($this->quality) ? $this->质量:0;
            休息;
       
        案例“bmp”:
            $image_create_func = 'ImageCreateFromBMP';
            $image_save_func = 'ImageBMP';
            $new_image_ext = 'bmp';
            休息;
       
        案例“gif”:
            $image_create_func = 'ImageCreateFromGIF';
            $image_save_func = 'ImageGIF';
            $new_image_ext = 'gif';

            休息;
       
        case 'vnd.wap.wbmp':
            $image_create_func = 'ImageCreateFromWBMP';
            $image_save_func = 'ImageWBMP';
            $new_image_ext = 'bmp';
            休息;
       
        案例“xbm”:
            $image_create_func = 'ImageCreateFromXBM';
            $image_save_func = 'ImageXBM';
            $new_image_ext = 'xbm';
            休息;
       
        默认值:
            $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;
    }其他{
        $new_name = 基本名称($this->source);
    }
   
    $save_to = $this->save_to."/blog_insert_temp_".time().mt_rand(1,99).".".$new_image_ext;
    // 输出对象组成跟$_FILE变量一样 得到后自己和昨天图片上传处理一样了
    $img_info['name'] = basename($this->source);
    $img_info['type'] = $mime;
    $img_info['尺寸'] = 1000;
    $img_info['tmp_name'] = $save_to;
    $img_info['错误'] = 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);
            }其他{
               $save_image = $image_save_func($img, $save_to);
            }
          
    }
         返回 $img_info;
    }

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板