这就是在laravel中验证视频文件的方法吗?

$validator = Validator::make(Input::all(),
  array(
    'file'  => 'mimes:mp4,mov,ogg | max:20000'
  ) 
);

because even if the file uploaded is a mov type, it will return that the file should be one of the types listed in the rule above.


How I ended up solving it:

根据下面的答案提示,我最终将上传文件的MIME类型存储到一个$mime变量中,如下所示:

$file = Input::file('file');
$mime = $file->getMimeType();

然后必须编写一条if语句来判断视频MIME类型:

if ($mime == "video/x-flv" || $mime == "video/mp4" || $mime == "application/x-mpegURL" || $mime == "video/MP2T" || $mime == "video/3gpp" || $mime == "video/quicktime" || $mime == "video/x-msvideo" || $mime == "video/x-ms-wmv") 
{
  // process upload
}

推荐答案

That code is checking for the extension but not the MIME type. You should use the appropriate MIME type:

 Video Type     Extension       MIME Type
Flash           .flv            video/x-flv
MPEG-4          .mp4            video/mp4
iPhone Index    .m3u8           application/x-mpegURL
iPhone Segment  .ts             video/MP2T
3GP Mobile      .3gp            video/3gpp
QuickTime       .mov            video/quicktime
A/V Interleave  .avi            video/x-msvideo
Windows Media   .wmv            video/x-ms-wmv

如果您不确定正在测试的文件的MIME类型,可以try $file->getMimeType()

Laravel相关问答推荐

AJAX响应中未定义的全名

如何获取多态多对多关系子查询的自动 id 列名?

无法找到用户sail:passwd 文件中没有匹配的条目

在 Laravel 包中的路由上使用显式或隐式模型绑定

laravel render() 方法有什么用?

Laravel API 版本控制文件夹 struct

Guzzle - Laravel如何使用 x-www-form-url-encoded 发出请求

导航栏品牌中的 Laravel 动态页面标题

在 Eloquent 中按自定义顺序对集合进行排序

在 laravel 6.0 中未定义命令ui

如何在 Laravel 查询中使用多个 OR、AND 条件

如何使用命令行手动运行 laravel/lumen 作业(job)

如何将 Facebook PHP SDK 与 Laravel 5.4 集成?

在 Laravel 中,如何获取 *only* POST 参数?

如何运行artisan命令计划:在托管服务器上运行? (Laravel )

Laravel php artisan 服务于模仿 HTTPS

Laravel 隐藏属性.例如密码 - 安全

Laravel 5 - 判断日期是否是今天

Laravel Route 模型与关系绑定

如何在 laravel 表单验证错误消息中给出自定义字段名称