PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 22, 2022

[FIXED] Laravel - Video file validation

 January 22, 2022     laravel, php, validation     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing