好的,我正在上传一段视频,并验证文件类型.
根据文件:
mimes:foo,bar,...
The file under validation must have a MIME type corresponding to one of the listed extensions.
Basic Usage Of MIME Rule
'photo' => 'mimes:jpeg,bmp,png'
I'm uploading a wmv video, and my rules are so:
return [
'file' => ['required', 'mimes:video/x-ms-wmv']
]
我对Request::file('file')
做了print_r()
,我得到了以下数据:
Symfony\Component\HttpFoundation\File\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => SampleVideo.wmv
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => video/x-ms-wmv
[size:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 70982901
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[pathName:SplFileInfo:private] => C:\wamp\tmp\php6428.tmp
[fileName:SplFileInfo:private] => php6428.tmp
)
However I'm getting the error:
{"file":["The file must be a file of type: video\/x-ms-wmv."]}
I've tried changing the "mime type" to video/*
, wmv
(as per the docs) and also video/x-ms-wmv
yet none of them validate the file correctly.
正如你从print_r()
中看到的,mime类型Symfony得到了is video/x-ms-wmv
.
Am I doing something wrong? Or can Laravel/Symfony just not validate files well?
I appreciate the help
Edit
Ok, I opened validator.php
and added echo $value->guessExtension();
to the ValidateMimes()
method, and it outputs asf.
Why is Symfony outputting video\x-ms-wmv
, the file extension is wmv, I'm validating both of them, but Laravel is guessing asf
?!
对我来说,视频验证太不可靠了.