无法检索图像

时间:2018-03-10 17:40:09

标签: php curl

抱歉我的英语不好我在我的新网站上做了一个从旧博客中恢复的脚本,但是我无法获得这种链接而且我无法访问服务器设置"不幸的是低成本托管。 我可以毫无顾虑地恢复直接链接的图像,但我无法通过这种链接恢复图像

**the file and recover well with the correct size but the image is corrupt**

**http://hack.idleman.fr/action.php?action=get_resource_image&id=36** 
<pre>
downloadFile('http://hack.idleman.fr/action.php?action=get_resource_image&id=36','img/cms/toto.png');
</pre>
<pre>
function downloadFile($url, $path)
{
    $newfname = $path;
    $file = fopen($url, 'rb');
    if ($file) {
        $newf = fopen($newfname, 'wb');
        if ($newf) {
            while (!feof($file)) {
                fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
            }
        }
    }
    if ($file) {
        fclose($file);
    }
    if ($newf) {
        fclose($newf);
    }
}
</pre>

**or even with this code**

<pre>
downloadImage('http://hack.idleman.fr/action.php?action=get_resource_image&id=36','img/cms/toto.png');
function downloadImage($url,$filename){
    if(file_exists($filename)){
        @unlink($filename);
    }
    $fp = fopen($filename,'w');
    if($fp){
        $ch = curl_init ($url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
        $result = parse_url($url);
        curl_setopt($ch, CURLOPT_REFERER, $result['scheme'].'://'.$result['host']);
        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0');
        $raw=curl_exec($ch);
        curl_close ($ch);
        if($raw){
            fwrite($fp, $raw);
        }
        fclose($fp);
        if(!$raw){
            @unlink($filename);
            return false;
        }
        return true;
    }
    return false;
}
</pre>

0 个答案:

没有答案