Search code examples
phplaravelupload

Why am I getting an error trying to upload a large file?


I am using Laravel and want to upload a 3GB video but get this error:

Request Entity Too Large
The requested resource does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.
Apache/2.4.54 (Win64) OpenSSL/1.1.1p PHP/8.1.12 Server at 127.0.0.1 Port 80
419
Page Expired

My code:

if($request->has('videos_path')){
  $request->validate([
      'videos_path'=>'required|file|max:380928|mimetypes:video/mp4',
  ]);
  $extension = strtolower($request->videos_path->extension());
  $filename = time() . rand(100, 999) . '.' . $extension;
  $request->videos_path->getClientOriginalName = $filename;

  $request->videos_path->move('assets/admin/uploads/movies/videos', $filename);
  $data['videos_path']= 'assets/admin/uploads/movies/videos/'. $filename;
}

And in php.ini:

max_input_time=1080
post_max_size=4096M
upload_max_filesize= 4096M

Solution

  • I would advice no to upload large files as normal form field. Upload them as subsequent chunks.

    Chunked upload is the process of breaking a file into smaller pieces, upload 'as is' and glue pieces into original file on the server side.

    You can check this link for more detail.