dongsu7049 2012-06-16 23:33
浏览 64
已采纳

PHP:为什么这个图像无法下载?

Using PHP I'm trying to download/save the following image:

http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428

When you load this image in a browser, you can see it, but when I try to download it using several different methods, I get an 1 KB file that says that the product could not be found on the server.

I tried this with both the file_put_contents and the curl way. I even used the function get_web_page that I found somewhere on StackOverflow, to catch a possible redirect.

What else could be the reason that you can see the image in a browser, but no way to download it ?

UPDATE: Thanks to an error that was thrown trying out the different answers, I just found out the real cause of the problem. Somewhere in the process of scraping the html, the URL got & instead of & . I replace these now and every other method works now too... thanks all!

  • 写回答

2条回答 默认 最新

  • dongzhong5833 2012-06-16 23:45
    关注

    I just implemented a simple way to download and store and it worked:

    <?php
    
    $fileContent = implode("",file("http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428"));
    $fp = fopen("/tmp/image","w+");
    
    fwrite($fp, $fileContent);
    
    fclose($fp);
    
    ?>
    

    Are you behind a proxy? This could be the problem (you are with proxy configured but php not) ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大