The PHP upload_max_filesize
directive determines the maximum size, in bytes, of files that can be uploaded using PHP’s file upload feature. It is a configuration setting that can be modified in the PHP configuration file (php.ini) or in a specific script using the ini_set() function.
By default, the upload_max_filesize
value is set to “2M” (2 megabytes) in PHP. This means that the maximum file size for uploads is 2 megabytes unless explicitly changed. However, the actual maximum file size allowed for uploads also depends on other factors such as the post_max_size
directive, which limits the overall size of the entire HTTP POST request, including both the file data and any other form data.
To increase the maximum upload file size, you can modify the upload_max_filesize
directive in the php.ini file or use the ini_set()
function in your PHP script. For example, to set the maximum upload size to 10 megabytes, you can add the following line in your php.ini file or at the beginning of your script:
Step 1: Open php.ini file
We need to open the php.ini file in your linux machine, We can use the given command for the same and need to open with nano or vim editor.
sudo vim /etc/php/8.1/apache2/php.ini
Step 2: Go to Line number 850
after opening php.ini file we need to go to line 850, where we need to update the php upload size as per out need.
upload_max_filesize = 256M
Step 3: Restart Apache
Remember to also adjust the post_max_size directive accordingly if you need to handle larger file uploads. After modifying the php.ini file, you may need to restart your web server for the changes to take effect.
sudo systemctl restart apache2.service
Conclusion
That’s it! You have successfully fixed the php max upload size error on Ubuntu 22.04 LTS. Still you are having any issue, Feel free and leave a comment below.