【问题标题】:PHP: Check if file is displayable by browserPHP:检查文件是否可以通过浏览器显示
【发布时间】:2017-06-22 07:50:32
【问题描述】:

我想检查某个文件是否可以被浏览器播放。

现在,我正在这样做:

$playable = ['image/png', 'image/jpeg' ... 'video/mp4' ...];
if (isset($playable[mime_content_type($file)])) {
  // file is playable
}

有没有更好的方法来做到这一点?也许是现代浏览器可以播放的 MIME 类型列表?

【问题讨论】:

标签: php mime-types


【解决方案1】:

您可以根据 mime 类型的前半部分在适当的元素中提供内容。然后您可以使用onerror 事件处理程序来检测错误。

How does one use the onerror attribute of an img element

【讨论】:

    猜你喜欢
    • 2016-11-20
    • 2021-06-05
    • 2012-10-16
    • 1970-01-01
    • 2011-07-21
    • 2021-07-06
    • 2021-02-21
    • 1970-01-01
    • 2011-04-04
    相关资源
    最近更新 更多