Search code examples
phplaravelfilefile-upload

Max file size validation in laravel is not working properly


I have a simple form to upload the videos. I am trying to check the size of the file.

 use Illuminate\Support\Facades\Validator;

   function submit_videos(Request $req)
{  
    $validated = $req->validate([
        'video_name' => 'required|max:1024'  
    ]);
}

The name of the input is video_name and the input type is file

This accepts files of more than 1MB


Solution

  • Use the size rule. This takes an integer value in bytes so that you can specify the maximum allowed file size.

    $validated = $req->validate([
        'video_name' => 'required|max:1024|size:1048576'  
    ]);