> 写个函数,将 http://www.vividchanelhandbags.com/images/20000665.jpg 这个
> 图片保存到 gbagsell.com 的 images 目录下的 aaa.jpg 这个文件。
<?php
header("Content-Type:image/jpeg");
header("Content-disposition: attachment; filename=\"http://www.vividchanelhandbags.com/images/20000665.jpg\""); 
$url = "http://www.vividchanelhandbags.com/images/20000665.jpg";
$ch = curl_init($url);
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";      
$header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache'); //HEADER信息   
curl_setopt($ch,CURLOPT_HTTPHEADER,$header);      
//USER_AGENT   
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
curl_setopt( $ch, CURLOPT_USERPWD , "test:123789");
$response = curl_exec($ch);
echo $response;?>我现在只能实现下载,那两个站都在自己的服务器上,是不是要在服务器上执行脚本命令.exec 这个东西

解决方案 »

  1.   

    有时候我都好想把我的照片保存到http://www.google.com/intl/en_ALL/images/srpr/logo1w.png不过就是不行
      

  2.   


    $url = "http://www.vividchanelhandbags.com/images/20000665.jpg";
    $ch = curl_init($url);
    $useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";      
    $header = array('Accept-Language: zh-cn','Connection: Keep-Alive','Cache-Control: no-cache'); //HEADER信息   
    curl_setopt($ch,CURLOPT_HTTPHEADER,$header);      
    //USER_AGENT   
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
    curl_setopt( $ch, CURLOPT_USERPWD , "test:123789");
    $response = curl_exec($ch);$filename="images/aaa.jpg";
    touch($filename);
    $handle = fopen($filename,"rb+");
    flock($handle,LOCK_EX);
    fwrite($handle,$response);
    ftruncate($handle,strlen($response));
    fclose($handle);
    @chmod($filename,0777);
      

  3.   

    用curl+Imagemagick来实现,效果挺好的。function dowloadPic($url, $filename){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_URL, $url);
    $ret = curl_exec($ch);
    curl_close($ch);
    $magick_wand=NewMagickWand();
    MagickReadImageBlob($magick_wand, $ret);
    MagickWriteImage($magick_wand, $filename);
    $filesize = MagickGetImageSize($magick_wand);
    DestroyMagickWand($magick_wand);
    return $filesize;
    }