2

I want to upload a file smaller than 8 MB, but when I uploaded a file bigger than 8 MB, it showed this error message.

Warning: POST Content-Length of 15735885 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

I don't want to change any configuration in php.ini. I want to prevent this error message.

I am trying to validate it.

$validator = Validator::make($request->all(), [
                'photo' => 'required | mimes:jpeg,jpg,png | max:30000',
             ]);

if ($validator->fails()) {
    dd('Photo is bigger than 3 MB');
}

but it didn't work.

Mengseng Oeng
  • 753
  • 2
  • 7
  • 19
  • See this:- http://php.net/manual/en/features.file-upload.php or https://laravel.com/docs/5.0/validation and https://www.sitepoint.com/handle-file-uploads-php/ It will be helpful for you. – Mehadi Hassan Apr 20 '18 at 03:07
  • use `size:30000` it works for file size. – AH.Pooladvand Apr 20 '18 at 04:31
  • Use should try this solution https://stackoverflow.com/questions/46067336/laravel-max-upload-size-limitations – Nirali Apr 20 '18 at 05:08
  • You need to validate on the client(browser) side, prior to upload. https://stackoverflow.com/questions/11514166/check-file-size-before-upload – Mike Stratton Apr 20 '18 at 06:26
  • 3MB = 3072KB, that's mean you need to set `max:3000` instead of 30000 (~30MB) – Phuc Lam Apr 20 '18 at 07:10

2 Answers2

0

upload_max_filesize should not be greater than post_max_size in php.ini file. For example.

    post_max_size = 128M
    upload_max_filesize = 64M
pandesantos
  • 339
  • 2
  • 13
-4

try

if ($file->getClientSize() < 3145728) {
           //your code  here             
        }

this will reject files larger than 3Mb

$file should be the object you're uploading