Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

imJohnBon's avatar

File validation failing on larger files.

I currently have a form with a file upload, and on that file upload I have a validation that makes sure it's an image and also makes sure the size can't be any larger than 1000:


'profile_image' => 'max:1000|mimes:jpg,png,gif',

However, when I upload a file to the form that's really big, the whole page breaks and I get this:


The file "test.psd" exceeds your upload_max_filesize ini directive (limit is 2048 KiB).

But I don't understand, the validation rules I have set should stop it from even getting to this point. Also it's a .PSD! It's not even the correct mime type. But if I upload a smaller .PSD, it validates fine. So the issue seems to be with larger files.

0 likes
14 replies
bashy's avatar
bashy
Best Answer
Level 65

https://www.google.co.uk/#q=upload_max_filesize+php

You need to change your PHP settings to allow for larger uploads. PHP has limits on these for a number of things. POST size, upload size etc

Edit: /etc/php5/fpm/php.ini and change these values to something sensible.

NOTE: post_max_size should be larger than upload_max_filesize, this is what I use on normal sites (large forum with uploads).

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 125M

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20
10 likes
imJohnBon's avatar

@bashy Huh, so I guess I was just misunderstanding. I thought the validation would cut it off before PHP even got to the point of determining its size, but on second thought I suppose that may not make any sense.

edit: Also, thank you for your reply. It is appreciated. I'm going to try this out now.

bashy's avatar

Regardless, if you have upload_max_filesize set to 1M and you try POST a file which is 5MB, it won't even get to Laravel. Every file uploaded will go into the tmp folder, obviously it has to store it to process it.

imJohnBon's avatar

@bashy Great point. I don't have a ton of experience with dealing with file uploads so this has been a great lesson. Appreciate the help!

bashy's avatar

Not a problem, spent years learning about file uploads and POST data along with security. There's a hell of a lot to learn and I'm always learning new things!

1 like
Mubashar's avatar

And don't forget to restart your xampp or wamp after changing your php.ini

fahmi's avatar

@bashy so my conclusion based on your conversation is, we always need to do client side check to make sure the files don't exceed post_max_size because chances are user can still try to upload files larger than post_max_size. Am I correct?

bashy's avatar

@fahmi The client can't upload more than the PHP limit set but it's always good to do client side validation to help give errors to normal users.

Firemaps's avatar

I have just edited my php.ini on php 7 for a live server .. do I need to run some command to init the changes? I am still getting the same FileException in UploadedFile.php line 235: The file "11111.jpg" exceeds your upload_max_filesize ini directive (limit is 2048 KiB).

Also, what is the point of making similar edits on ngix.conf?

gobi's avatar

using file chunk method , chunk 50 mb files divide by 2mb,2mb,2mb..like this.. is this possible to upload file like this in laraval & jquery? without changing php.ini configuration @bashy @fahmi

elo's avatar

@bashy I have made the changes to my php.ini file and restarted wamp and then shutdown and restarted my system. Issue is that I'm still getting the error

The file "20161118_120328.jpg" exceeds your upload_max_filesize ini directive (limit is 2048 KiB).

Inside my php.ini file, here are the edits

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
post_max_size = 125M

I have no idea why the changes won't work.

bashy's avatar

@elo

  1. Confirm with phpinfo() in a file via the web.
  2. Check nginx (if you use it) as that has limits too.
nima_sh's avatar

check if you change php.ini of your correct version of php . i have same problem with my wamp , when i change 'max_file_uploads = 20' it changes my php5 ini file but i use php7 .

Please or to participate in this conversation.