seamuswc's avatar

Laravel validation misreading file extension?

I have a simple file upload system.

It works for jpegs, png, but when I try to upload a 4mb .mp4 file it says the file is not an mp4.

exact file name is: lb1.mp4

On right click get info i get following. Kind: MPEG-4 movie

$validator = Validator::make($request->all(), [
       'file' => 'required|file|max:5000|mimes:jpeg,png,mp4,ogg,mp4s'
    ]);

    if ($validator->fails()) {
         return redirect($channel)
                    ->withErrors($validator)
                    ->withInput();
    }

Error returned is: "The file must be a file of type: jpeg, png, mp4, ogg, mp4s."

is there another mime i should add onto the validation. I looked at the apache mime list and added 'mp4s'. still no luck.

0 likes
2 replies
aurawindsurfing's avatar

Hey @seamuswc

Found on StackOverflow https://stackoverflow.com/questions/22378742/laravel-video-file-validation/26262561 it was also laravel related question:

 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

Maybe your file is one of them?

sin2san's avatar

You can check using an if condition in the controller if this issue still persists.

$extension = $request->video->getClientOriginalExtension();
            if($extension !== 'mp4'){
                return redirect()->back()->with('error', 'You can only upload mp4 files');
            }

Please or to participate in this conversation.