对方网站有一个HTTPS的图片
https://public.lightpic.info/image/B19A_5952792E0.jpg
我想在我的服务器上运行PHP
把这个图片下载保存到服务器上

解决方案 »

  1.   

    file_get_contents 就能获取file_put_contents('B19A_5952792E0.jpg',file_get_contents('https://public.lightpic.info/image/B19A_5952792E0.jpg'));
    echo '<img src="B19A_5952792E0.jpg">';
      

  2.   

    file_get_contents是无法下载HTTPS图片的
      

  3.   

    $url = 'https://public.lightpic.info/image/B19A_5952792E0.jpg';
    function getImg($url) {    $ch = curl_init ();
        curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
        curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );//跳过ssl验证
        curl_setopt ( $ch, CURLOPT_URL, $url );
        ob_start ();
        curl_exec ( $ch );
        $return_content = ob_get_contents ();
        ob_end_clean ();
        return $return_content;
    }
    $return_content = getImg($url);
    $filename = 'test.jpg';
    $fp= fopen($filename,"a");
    fwrite($fp,$return_content); //写入文件
      

  4.   

    我下载下来的文件是0KB 你用的是什么PHP集成环境 我用的是PHPNOW
      

  5.   

    你的 url 是错误的,当然不行!
      

  6.   

    php.ini中打开extension=php_openssl.dll1楼代码可以执行,没打开之前得到文件是0kbfile_put_contents('kkk.jpg',file_get_contents('https://public.lightpic.info/image/B19A_5952792E0.jpg'));
    echo '<img src="kkk.jpg">';
      

  7.   

    curl就可以了
    https://segmentfault.com/q/1010000008502236