做过手机端微信和微博登陆接口
他们提供的图片地址是可以file_get_contents()的
然后直接file_put_content()保存在本地文件夹,至于路径和命名规则自己定
保存远程图片应该封装一个函数
然后把本地路径保存在服务器上

解决方案 »

  1.   

    function put_file_from_url_content($url, $saveName, $path) {
        // 设置运行时间为无限制
        set_time_limit ( 0 );
        
        $url = trim ( $url );
        $curl = curl_init ();
        // 设置你需要抓取的URL
        curl_setopt ( $curl, CURLOPT_URL, $url );
        // 设置header
        curl_setopt ( $curl, CURLOPT_HEADER, 1 );
        // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
        curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
        // 运行cURL,请求网页
        $file = curl_exec ( $curl );
        // 关闭URL请求
        curl_close ( $curl );
        // 将文件写入获得的数据
        $filename = $path . $saveName;
        $write = @fopen ( $filename, "w" );
        if ($write == false) {
            return false;
        }
        if (fwrite ( $write, $file ) == false) {
            return false;
        }
        if (fclose ( $write ) == false) {
            return false;
        }
     }put_file_from_url_content($userAvatar, $userOpenId.".jpg", $avatarPath);