douhuai4155 2013-03-02 09:47
浏览 307
已采纳

如何通过PHP中的URL获取图像的内容?

I am using an api of a SNS website, which is uploading an image. This api has a parameter "photo=photo_file_content", and is basing on RFC 1867.

Now I have the url of a certain image, but I don't kwon how to fetch the image, I've used $param['photo'] = file_get_contents($pic_path); , but it didnt' work.

So what's the proper way to get the image? Thanks.

  • 写回答

1条回答 默认 最新

  • dtpt75860 2013-03-02 10:02
    关注

    You can use Client URL Library. It is the best solution for you.

    Also, try this:

    $ch = curl_init ($url);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
            $gm=curl_exec($ch);
            curl_close ($ch);
    

    and save the result $gm in a file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作