Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The file exceeds your upload_max_filesize ini directive (limit is 2048 KiB) in Laravel

I'm getting the above error in my development environment when i try to upload an image. I have followed other answers here by doing the following

  • Setting the upload_max_filesize and post_max_size
  • Restart wamp server
  • Shutdown system and restarted the system

but i still can't get past the error. Am I doing anything wrong? Below is the relevant section from my php.ini file

; 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
like image 446
Mena Avatar asked Dec 03 '22 21:12

Mena


2 Answers

If you're using LAMP (Apache server), you need to edit both /etc/php/7.2/cli/php.ini and /etc/php/7.2/apache2/php.ini.

Properties to edit to the desired values (ex. 10 Megabytes):

  1. upload_max_filesize: default is 2M (Megabytes) ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 10M
  2. post_max_size: default is 8M (Megabytes) ; 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 = 10M

After saving the php.ini files, run: sudo service apache2 restart

Note: before editing the php.ini values, ensure that /etc/php/7.2/apache2/php.ini is the loaded php configuration file. The command is: php -i | grep php.ini

like image 102
elenche Avatar answered Dec 06 '22 09:12

elenche


I agree with you. I am developing a project with Laravel, and the PHP version I use is 7.2, but the upload_max_filesize = 100M line that I was changing when I made changes from the WAMP server was the php.ini file for PHP 5.

I created a blank page in my project and found where the php.ini file was with the phpinfo() command.

File path in me: C:\wamp64\bin\php\php7.2.4\php.ini

And I was shocked when I saw that the line upload_max_filesize was 2M. When I made the change, I restarted the services and I am happy!

like image 27
B. Kuday GORUN Avatar answered Dec 06 '22 10:12

B. Kuday GORUN