doujie1908 2017-11-14 17:36
浏览 76
已采纳

如何通过PHP从这个URL保存图像

I have URLs like this:

https://strg.global/getImage.php?app=mgm&type=adinda-kennedy&imgId=MGM%20Adinda%20Kennedy%20e6057b8e-aa68-4461-8c9a-1d069fc021a4.jpg&size=1080&cachebreaker=1500536003696`

When you visit it the image downloads automatically.

How can I get and save it via PHP?

I've tried file_get_content(), but it returned info in inappropriate format for saving. I've tried to use Intervention image library and it's method Image::make($url), but it hasn't worked either.

  • 写回答

1条回答 默认 最新

  • dongzuo7166 2017-11-14 19:00
    关注

    Get the content from the URL, then create an image from the string you get back with (surprisingly) "imagecreatefromstring". After you have the image you can simply display it or save it :

    $Res = file_get_contents($URL);
    $Img = imagecreatefromstring($Res);
    imagepng($Img,"FileName.png");
    imagedestroy($Img);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 模电中二极管,三极管和电容的应用
  • ¥15 关于模型导入UNITY的.FBX: Check external application preferences.警告。
  • ¥15 气象网格数据与卫星轨道数据如何匹配
  • ¥100 java ee ssm项目 悬赏,感兴趣直接联系我
  • ¥15 微软账户问题不小心注销了好像
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络