php - 在 PHP 中查找远程/外部文件 mimetypes

标签 php url external mime-types

出于防止恶意或不需要的文件类型的安全目的,我如何从外部/远程文件(也称为 www.someurl.com/video.avi 之类的 url 链接)中识别 mime 类型?我读过有一种使用 cURL 的方法,但如果可能的话,我想找到一个 PHP native 解决方案。

最佳答案

您可以使用 get_headers

例子:

<?php

$headers = get_headers('http://website.com/image.png');
var_dump($headers);

?>

输出:

array(8) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Tue, 08 May 2012 07:56:54 GMT"
  [2]=>
  string(14) "Server: Apache"
  [3]=>
  string(44) "Last-Modified: Sun, 06 May 2012 23:09:55 GMT"
  [4]=>
  string(20) "Accept-Ranges: bytes"
  [5]=>
  string(22) "Content-Length: 707723"
  [6]=>
  string(17) "Connection: close"
  [7]=>
  string(23) "Content-Type: image/png"
}

关于php - 在 PHP 中查找远程/外部文件 mimetypes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10492575/

相关文章:

css - angular2 : how to manually add css files by condition to index. html?

php - 在 MySQL 中存储 HTML

php - 路由不适用于 Slim 框架

PHP:系统找不到指定的路径

perl - 如何从 Perl 中的 URL 中仅提取方案、主机和端口?

html - 背景图像存在但不可见

javascript - 选择表,检查并在值匹配时提示

apache - 明显重写的 URL 重写(更改地址栏中的 URL)

android - 我们可以从外部硬盘构建android吗

xml - 外部 dtd (xml) 中的外部实体引用