Ok, I'm trying to upload a video, and validate the file type.
According to the documentation:
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']
]
I've done a print_r()
on Request::file('file')
and I get the following data:
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.
As you can see from the print_r()
the mime type Symfony is getting 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
?!
It's too unreliable for video validation for me.