douyan2680 2013-08-09 13:57
浏览 23

确定链接的内容

Is there any PHP function that defines whether a given link is a video, picture or neither.

For example:

$link = www.example.com/342kddd23
$a = phpfunction($link);

If $link is a video link; $a = 1, if $link is a picture link $a = 2, if $link is not defined (it could be a normal link) $a = 0.

Is that possible? If so, are there any existing functions like that?

  • 写回答

2条回答 默认 最新

  • dphphvs496524 2013-08-09 14:01
    关注

    I don't believe such a library exists (there's no built-in function I'm aware of).

    You could of course attempt to develop your own, but you'll endlessly be chasing your tail if you plan to go beyond simply checking to see if there's a known file extension such as ".mp4", ".png", etc. due to the fact that you'll need to construct an increasingly large list of matching URL schemas. (This would also imply that a given link may only return a single type of content, which is often not the case.)

    Assuming that you're looking for video and image files themselves (and not simply URLs that contain a video, etc.) an alternative (more accurate) approach would be request each link (perhaps using cURL with CURLOPT_HEADER enabled), see what content headers are returned (specifically "Content-Type") and take things from there.

    Update

    As a follow-up based on @smassey's excellent comment, setting the CURLOPT_NOBODY option (once again via curl_setopt) will send a HEAD request, hence ensuring you don't actually download any of the content beyond the response headers themselves.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP