Issue
Is this how to validate a video file in 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:
As prompted from the answer's below I ended up storing the mime type for the uploaded file to a $mime
variable like so:
$file = Input::file('file');
$mime = $file->getMimeType();
Then had to write an if statement to check for video mime types:
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
}
Solution
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
If you are not sure the MIME type of the file you are testing you can try $file->getMimeType()
Answered By - marcanuy
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.