dongmie3526 2017-07-08 13:39
浏览 172
已采纳

如何在没有扩展名的情况下判断图像的文件类型? 他们是如何工作的?

I am dealing with images on the web that come without a file extension, like this:

https://static1.squarespace.com/static/52a74d9ae4b0253945d2aee9/t/52ed63b1e4b04368c021b921/1463088116168/?format=500w

Images like these can be found, e.g., on websites made with squarespace, like this demo: https://bedford-demo.squarespace.com/

I'm trying to download these images and store them on my server, using PHP. But how can I find out the actual URL of those images? How does this work? And how can I tell the filetype of this image? What is this sorcery?

Any hints are appreciated!

  • 写回答

2条回答 默认 最新

  • dsjq62428 2017-07-08 13:43
    关注

    Quick answer:

    To find out the Content-Type returned for any URL, look at this answer:
    Get Content-Type of requested URL in PHP


    Why you need the Content-Type:

    Just like how not every webpage on the internet has an URL that ends with .html, images are not required to have an "extension" in their URL either.

    What determines whether the browser will treat the data retrieved from the URL as an image is the Content-Type header in the HTTP response.

    The URL you posted returns the following HTTP headers:

    enter image description here

    For HTML documents the Content-Type is text/html. You can inspect the headers as you browse by opening the Network tab of the developer console in your browser. Look for the "response headers".

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?