php - 使用 PHP 检测链接内容类型

标签 php content-type

如何检测链接的内容类型?

用户可以将链接上传到您的网站。我需要将链接类型(视频、图像...)保存在数据库(mysql)中。

我用 Java 找到了一个答案(使用 HTTP HEAD): Selenium 2: Detect content type of link destinations 。不过我使用的是 PHP。

谢谢。

最佳答案

该解决方案抽象地也适用于 PHP。

检测链接目标内容类型的方法是执行 HTTP HEAD 请求(例如使用 PHP 的curl 扩展或 get_headers 函数),然后读取返回的 Content -键入 header 。

如果远程端无法访问,请确保优雅地失败。

关于php - 使用 PHP 检测链接内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9365401/

相关文章:

javascript - 使用纯 JavaScript 设置 AJAX 内容类型(无 JQuery)

php - Adyen API 401 未经授权

php - PHP中的分页问题

php - Aws S3 CompleteMultipartUpload 错误

php - 如何在cakephp中写内容类型?

header - 如果响应 header 包含内容类型,Content-Type 元标记是否重要?

javascript - Laravel 插入 2 个表

php - 如何在 PHP 中将日期和时间字符串转换为当前时区日期

java - 提供 BufferedImage 时 Spring MVC 内容协商失败

德鲁帕尔 6 : Drupal Themer gives same candidate name for different type of content types