Laravel file failed to upload due to size - php

I am using Laravel as an API when I try to upload a file bigger than 2Mb I get error file failed to upload. I saw that it's related to php.ini file, I tried updating post_max_size and restart apache, but it didn't work. I don't know how to solve this error any help please.

To increaes file upload size in PHP, you need to modify the upload_max_filesize and post_max_size values in your php.ini file.
upload_max_filesize = 10M
post_max_size = 10M
You can also do it via .htaccess file.
Use echo phpinfo(); to check you variable values.
Don't forget to restart your apache service after changes.

Basically there are two php.ini files /etc/php/7.4/apache2/php.ini that I was making changes to. But Laravel was using /etc/php/7.4/cli/php.ini and I had to dd(php_ini_loaded_file()); which gives the path to the loaded php.ini file. After making changes to that file and restarting apache2 server the problem was solved.

Related

PHP Can't upload large video to the SQL database [duplicate]

I am getting this error when trying to upload an import on WordPress on my XAMPP local dev environment:
Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
I changed the upload_max_filesize from 2M to 1000M, but that didn't seem to do anything.
Any ideas?
8388608 bytes is 8M, the default limit in PHP. Update your post_max_size in php.ini to a larger value.
upload_max_filesize sets the max file size that a user can upload while
post_max_size sets the maximum amount of data that can be sent via a POST in a form.
So you can set upload_max_filesize to 1 meg, which will mean that the biggest single file a user can upload is 1 megabyte, but they could upload 5 of them at once if the post_max_size was set to 5.
Changes will take effect after a restart of the server.
Just set these in php.ini:
upload_max_filesize = 1000M;
post_max_size = 1000M;
1. First u will find the php.ini file.
u can find php.ini file from this path. C:\xampp\php or from
xampp folder.
2. Now open php.ini file and change the following:
1. post-max-size (change 8M to 800M).
2. upload-max-filesize (change 2M to 2000M).
3. Now stop the Apache server and MySQL.
4. Now restart Apache server and MySQL.
It worked fine after that.
Enjoy ur working now :)
That's an 8MB post_max_size error.
Set it to a value you're comfortable with.
You will have to change the value of
post-max-size
upload-max-filesize
both of which you will find in php.ini
Restarting your server will help it start working. On a local test server running XAMIP, i had to stop the Apache server and restart it. It worked fine after that.
Already restarted your Webserver?
This will force php to reload the php.ini
Go to C:\xamppp\php. Set these values in php.ini:
upload_max_filesize = 1000M
post_max_size = 0M
Create new text file in your wp-admin directory root and name it info.php.
Open info.php and add this line:
<?php phpinfo(); ?>
Save it.
Go to yourwebsitename(probably localhost)/wp-admin/info.php in any web-browser.
On the 8th line you will see: Configuration File (php.ini) Path, in my case it is C:\Windows, meaning it is located on my C drive.
In the 9th line you will see: Loaded Configuration File, and next to it is written C:\xampp\php.ini
So I found my php.ini page that is associated with my wordpress web-site.
Go to that path, and find php.ini.
Open it, and edit:
Search for post_max_size=8M, and change it to post_max_size=1000M
Search for upload_max_filesize=2M, and change it to upload_max_filesize=1000M
Go back to your Admin page → Media → Add New
On the bottom you will see that 2MB has changed to 1000M.
Once you done this process then you must restart your web server or just restart your computer.
Find php.ini [\xampp\php]
Just set these in php.ini:
upload_max_filesize = 1000M;
post_max_size = 1000M;
Rebot server
Stop Apache and MySQL
Start again Apache and MySQL
Go to
C:\drive\xampp(where xampp installed)
simply find php.ini file then in the file search
post_max_size=XXM
upload_max_size=XXM
Change with this code
post_max_size=100M
upload_max_filesize=100M
Don't forget to restart the xampp
Using wamp do the following and hopefully, it will resolve an issue
Make these changes in PHP Options to correct:
max_execution_time 180
memory_limit 512M or your highest available
post_max_size 32M
upload_max_filesize 64M
You also need the change post-max-size.
From the XAMPP panel, click on the ADMIN button on the Apache site.
Then choose to edit php.ini
And add the missing post_max_size to a value you are comfortable with.
post_max_size = 100M
Go to
C:\ drive
or that drive where xampp is installed
click on xampp
find php and open it , there you find php.ini folder
open php.ini file with notepad and find upload_max_filesize and post_max_size in both "up and down find option",change both values to 1000M
I have fixed same issue by changing below parameters to expected value in /etc/php/7.2/apache2/php.ini file
upload_max_filesize = 8M;
post_max_size = 8M;
upload_max_filesize = 8M;
post_max_size = 8M;
Imagine you already changed above values. But what happen when user try to upload large files greater than 8M ?
This is what happen, PHP shows this warning!
Warning: POST Content-Length of x bytes exceeds the limit of y bytes in Unknown on line 0
you can avoid it by adding
ob_get_contents();
ob_end_clean();
You have 2 options for this error:
The file you are uploading is too big, which you need to use smaller file.
Increase the upload size in php.ini to
upload_max_filesize = 9M; post_max_size = 9M;
Go to browser and search for php.ini and then open it, and change these two values:
post_max_size= 1000000000000M
upload_max_filesize= 10000000000000M
If you open the php.ini file using notepad , you can search for these two values by clicking:
cmd + f
You might not be uploading the right zip file. In my case, as a newbie to wordpress(I used to do hardcoding), I installed the zipped file that contained another zip file which is the actual theme neede to be upload. So what what need to do in this case is to unzip the file and locate the "theme_name.zip" inside.
If changing the post_max_size settings from XAMPP folders. It did not work for you try this.
From XAMPP control panel, click config then PHP (php.ini) and edit post_max_size and upload_max_filesize to a higher number in this file instead. Stop Apache server. Start Apache server. This worked for me.
If your objective is to import a theme into your Wordpress then you can manually copy paste your theme into your wp-content->themes folder and extract it of course. I just encountered this and couldn't locate the php.ini file for WAMP.
I have solved my php7 issues on centos 7 by updating /etc/php.ini with these settings:
post_max_size = 500M
upload_max_filesize = 500M
for anyone running PHPMyAdmin inside of docker.
Set the UPLOAD_LIMIT value in the env
from the docs https://github.com/phpmyadmin/docker#environment-variables-summary
UPLOAD_LIMIT - if set, this option will override the default value
for apache and php-fpm (format as [0-9+](K,M,G) default value is
2048K, this will change upload_max_filesize and post_max_size
values)
docker-compose.yml example:
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- UPLOAD_LIMIT=300M
normal docker run:
sudo docker run .... -e UPLOAD_LIMIT=300M
For both of these options you have to rebuild the container
As Optimaz ID pointed out, the code below helped me hide the PHP error message in a case where the user uploads a file larger than the upload_max_filesize and post_max_size set in php.ini (which is almost impossible when a large value is set).
ob_get_contents();
ob_end_clean();

Erro Upload Video into my database [duplicate]

I am getting this error when trying to upload an import on WordPress on my XAMPP local dev environment:
Warning: POST Content-Length of 8978294 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
I changed the upload_max_filesize from 2M to 1000M, but that didn't seem to do anything.
Any ideas?
8388608 bytes is 8M, the default limit in PHP. Update your post_max_size in php.ini to a larger value.
upload_max_filesize sets the max file size that a user can upload while
post_max_size sets the maximum amount of data that can be sent via a POST in a form.
So you can set upload_max_filesize to 1 meg, which will mean that the biggest single file a user can upload is 1 megabyte, but they could upload 5 of them at once if the post_max_size was set to 5.
Changes will take effect after a restart of the server.
Just set these in php.ini:
upload_max_filesize = 1000M;
post_max_size = 1000M;
1. First u will find the php.ini file.
u can find php.ini file from this path. C:\xampp\php or from
xampp folder.
2. Now open php.ini file and change the following:
1. post-max-size (change 8M to 800M).
2. upload-max-filesize (change 2M to 2000M).
3. Now stop the Apache server and MySQL.
4. Now restart Apache server and MySQL.
It worked fine after that.
Enjoy ur working now :)
That's an 8MB post_max_size error.
Set it to a value you're comfortable with.
You will have to change the value of
post-max-size
upload-max-filesize
both of which you will find in php.ini
Restarting your server will help it start working. On a local test server running XAMIP, i had to stop the Apache server and restart it. It worked fine after that.
Already restarted your Webserver?
This will force php to reload the php.ini
Go to C:\xamppp\php. Set these values in php.ini:
upload_max_filesize = 1000M
post_max_size = 0M
Create new text file in your wp-admin directory root and name it info.php.
Open info.php and add this line:
<?php phpinfo(); ?>
Save it.
Go to yourwebsitename(probably localhost)/wp-admin/info.php in any web-browser.
On the 8th line you will see: Configuration File (php.ini) Path, in my case it is C:\Windows, meaning it is located on my C drive.
In the 9th line you will see: Loaded Configuration File, and next to it is written C:\xampp\php.ini
So I found my php.ini page that is associated with my wordpress web-site.
Go to that path, and find php.ini.
Open it, and edit:
Search for post_max_size=8M, and change it to post_max_size=1000M
Search for upload_max_filesize=2M, and change it to upload_max_filesize=1000M
Go back to your Admin page → Media → Add New
On the bottom you will see that 2MB has changed to 1000M.
Once you done this process then you must restart your web server or just restart your computer.
Find php.ini [\xampp\php]
Just set these in php.ini:
upload_max_filesize = 1000M;
post_max_size = 1000M;
Rebot server
Stop Apache and MySQL
Start again Apache and MySQL
Go to
C:\drive\xampp(where xampp installed)
simply find php.ini file then in the file search
post_max_size=XXM
upload_max_size=XXM
Change with this code
post_max_size=100M
upload_max_filesize=100M
Don't forget to restart the xampp
Using wamp do the following and hopefully, it will resolve an issue
Make these changes in PHP Options to correct:
max_execution_time 180
memory_limit 512M or your highest available
post_max_size 32M
upload_max_filesize 64M
You also need the change post-max-size.
From the XAMPP panel, click on the ADMIN button on the Apache site.
Then choose to edit php.ini
And add the missing post_max_size to a value you are comfortable with.
post_max_size = 100M
Go to
C:\ drive
or that drive where xampp is installed
click on xampp
find php and open it , there you find php.ini folder
open php.ini file with notepad and find upload_max_filesize and post_max_size in both "up and down find option",change both values to 1000M
I have fixed same issue by changing below parameters to expected value in /etc/php/7.2/apache2/php.ini file
upload_max_filesize = 8M;
post_max_size = 8M;
upload_max_filesize = 8M;
post_max_size = 8M;
Imagine you already changed above values. But what happen when user try to upload large files greater than 8M ?
This is what happen, PHP shows this warning!
Warning: POST Content-Length of x bytes exceeds the limit of y bytes in Unknown on line 0
you can avoid it by adding
ob_get_contents();
ob_end_clean();
You have 2 options for this error:
The file you are uploading is too big, which you need to use smaller file.
Increase the upload size in php.ini to
upload_max_filesize = 9M; post_max_size = 9M;
Go to browser and search for php.ini and then open it, and change these two values:
post_max_size= 1000000000000M
upload_max_filesize= 10000000000000M
If you open the php.ini file using notepad , you can search for these two values by clicking:
cmd + f
You might not be uploading the right zip file. In my case, as a newbie to wordpress(I used to do hardcoding), I installed the zipped file that contained another zip file which is the actual theme neede to be upload. So what what need to do in this case is to unzip the file and locate the "theme_name.zip" inside.
If changing the post_max_size settings from XAMPP folders. It did not work for you try this.
From XAMPP control panel, click config then PHP (php.ini) and edit post_max_size and upload_max_filesize to a higher number in this file instead. Stop Apache server. Start Apache server. This worked for me.
If your objective is to import a theme into your Wordpress then you can manually copy paste your theme into your wp-content->themes folder and extract it of course. I just encountered this and couldn't locate the php.ini file for WAMP.
I have solved my php7 issues on centos 7 by updating /etc/php.ini with these settings:
post_max_size = 500M
upload_max_filesize = 500M
for anyone running PHPMyAdmin inside of docker.
Set the UPLOAD_LIMIT value in the env
from the docs https://github.com/phpmyadmin/docker#environment-variables-summary
UPLOAD_LIMIT - if set, this option will override the default value
for apache and php-fpm (format as [0-9+](K,M,G) default value is
2048K, this will change upload_max_filesize and post_max_size
values)
docker-compose.yml example:
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
- UPLOAD_LIMIT=300M
normal docker run:
sudo docker run .... -e UPLOAD_LIMIT=300M
For both of these options you have to rebuild the container
As Optimaz ID pointed out, the code below helped me hide the PHP error message in a case where the user uploads a file larger than the upload_max_filesize and post_max_size set in php.ini (which is almost impossible when a large value is set).
ob_get_contents();
ob_end_clean();

The uploaded file exceeds the upload_max_filesize directive in php.ini error while uploading plugin

When I tried to upload a plugin for my Wordpress template in wamp 2.0 I got an error:
The uploaded file exceeds the upload_max_filesize directive in php.ini
How to fix this error?
Seeing as though you've mentioned WAMP, I'm going to assume you can edit the php.ini file?
If you left click on the WAMP icon in the status bar, select the PHP menu and then click on the php.ini file in that menu. Just open it in Notepad is fine.
Then in Notepad, do a search (CTRL+F) for "upload_max_filesize", and then you can change the value that is set there.
I don't remember what the default is, but for mine, I have it set to "200M" (without the quotes). This means 200mb.
Save the file, close it, and then restart WAMP.
You should then be right to upload your plugin
We have seen this error at least once if we have used WordPress.When installing a theme, plugin or uploading an image or file, It has nothing to do with the theme or plugin. The issue is with our server settings which limit the maximum size for uploaded files.
It’s a common error and it can be easily fixed. This error message is an indication of that the file you are trying to upload is larger than your web host allows (WordPress default file upload size is 2 MB).
The uploaded file exceeds the upload_max_filesize directive in php.ini
Solution:
A solution is easy, need to increase the file size upload limit.
If using WordPress on a local machine using XAMPP, we will find the php.ini in the following locations.
Windows: C:/xampp/php/php.ini
Open the php.ini file. Find these lines in the php.ini file and replace it following numbers
upload_max_filesize = 64M
Save the changes and refresh your website and try uploading the file again. You will now get success.
In Wamp > PHP > php.ini file, put or edit these lines, and then restart your Wamp server.
post_max_size = 750M
upload_max_filesize = 750M
max_execution_time = 5000
max_input_time = 5000
memory_limit = 1000M
This error is because your upload_max_filesize variable in php.ini file is adjusted to 2Mb.. change it to 64Mb!!
This video tutorial will help you fixing your error in 60 seconds!! Hope it helps
A Solution is easy, you just want to add plugin in your WordPress.
Download your .zip file of plugin.
Extract the .zip file.
Now, upload the extracted folder to ../wp-content/plugins/ location.
Go to the Installed Plugins page in WordPress, Now you can see the plugin is there, which you have recently uploaded.
Finally, click activate link.
Open your xampp software and click on config button in front of apache option and select php.ini option
Next find this code
upload_max_filesize=2M
and replace with this code
upload_max_filesize=64M
Now restart apache and mysql and enjoy it
I use MAMP. To locate the 'php.ini' file, if you also use MAMP, the way Is as follows:
Go to the folder location where the MAMP is installed. For example, 'C:\MAMP' Is the folder location of MAMP.
Go to 'conf' folder.
From 'localhost:8888/MAMP', you will get 'phpinfo' link under PHP section. Click on the link and from the directed page, get the version of PHP is installed into your system.
From 'conf' folder, go to the folder with the version of PHP you got in the previous step.
Go to that folder and you will get the required php.ini file.
Open that file in any text editor and update the info:
(memory_limit = 64M, upload_max_filesize = 128M, post_max_size = 512M)
Restart MAMP.
Then you are good to go for uploading big files into your local server.
Find this line in the php.ini file upload_max_filesize = 2M and replace it with a higher value (e.g. upload_max_filesize = 64M)
And restart wamp..!
If you're using WAMP 2 you should update to Release 3.2.3.x with the GUI you can set upload_max_filesize to 64MB recommended to do so follow the instructions.
Click WAMP icon at taskbar
Go to PHP
PHP Settings
Find "upload_max_filesize" and select the size
Locate the php.ini file in your local dir. I use Xampp. =>C:\Xampp. Now find the line where it says
upload_max_filesize = 2M
and change this to your desired value.
upload_max_filesize = 56M
Restart all your services and you should be able to upload your new files.
Windows: C:/xampp/htdocs/wordpress_project/.htaccess
php_value upload_max_filesize 1000M
php_value post_max_size 2000M
php_value memory_limit 3000M
php_value max_execution_time 180
php_value max_input_time 180
// in end tag of wordpress

Getting trouble while uploading a file in PHP

I'm using PHP as server side programming,I'm facing a different type of problem while uploading the images.If the uploading image is having below 8MB is uploading fine but if image size is increases then its not uploading.What might be the problem.I know I've to change in php.ini file,but where I don't know.please help me
Yes,you need to change a upload_max_filesize value to your desired value in php.ini file.After that you have to restart the server
You need to establish first where your PHP.ini is coming from. If you create a PHP script with this one line of code in it and access it in your browser, that will tell you:
phpinfo();
(Mine says: Loaded Configuration File /etc/php5/apache2/php.ini )
Then edit that file and alter the lines
post_max_size = 8M
upload_max_filesize = 8M
to something more appropriate. Then restart Apache. You may be able to use the .htaccess method in vlzvl's answer, but I'd say probably not.
open you .htaccess and write:
php_value upload_max_filesize 16M
php_value post_max_size 16M

How to import table in phpmyadmin? I got error of file size

I want to import database in phpmyadmin but i got error like this...
"No data was received to import. Either no file name was submitted, or the file size exceeded the maximum size permitted by your PHP configuration."
my file size is 4.8 mb,
please give me solution....
Follow theses steps
Go to the PHP folder -> search for php.ini
Seach for the below line and change it according to your need.
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
Restart the server to confirm changes.
try to edit after change into php.ini :
upload_max_filesize = 10M
post_max_size = 20M
memory_limit = 128M
also change the value of max_execution_time
EDIT:
if you want then do all that stuff with command line:
mysql -h[Host Name] -u[User Name] [Database Name]<[SQL File Name] -p
through this you will import the database..
Copy the data from the file, put it into the sql tab of phpmyadmin, and press the "Go" button.
You need to edit the php.ini file for changing the file size. the line is
upload_max_filesize = 2M
You need to change the file size that you need to import.For ex: if you need to import a 10 mb file,then change it into
upload_max_filesize = 10M
Then restart your server.
I had the same problem. Here is the solution:
you need to edit the variable for max_upload_size in php.ini file
so do the following:
locate php.ini
it will show you the location of that file
enter the file by
sudo gedit /etc/php/7.0/apache2/php.ini
enter password
find the variable and edit the value to as much as you want
save it and exit
now restart your server
service apache2 restart
and done!!
You need to make sure that your file size options are set to suitable values in the correct file. On my system there are 3 files called php.ini inside /etc/php/7.0 (Linux Mint 18.1 Cinnamon) but only one of them is being used.
The instructions here tell you how to find which file to edit:
Create a file var/www/html/phpinfo.php. Paste this code into it and save it:
<?php phpinfo() ?>
Then in a browser navigate to http://localhost/phpinfo.php
This displays your php configuration, look for the option "Loaded Configuration File", it should be near the top of the page. This will give you the location of your php.ini file, on my system it's /etc/php/7.0/apache2/php.ini
Now open that file (don't forget to open it as root so you can save changes) and increase the allowed file size to a value larger than your sql file, for example:
upload_max_filesize = 20M
If that doesn't do the trick, you can try increasing the values for these settings also:
max_execution_time
max_input_time
memory_limit
post_max_size
Increase the upload file size limit in the server. If you don't have access to it try breaking the file into parts, for different tables. Or you may use MySQL Dumper.
I had the same problem with WAMP. I even tried changing the limit going back to php.ini for max_upload_limit but still it didn't work. I went back to my mac and tried on MAMP and i had no issues at all. BTW I figured out that... the max limit size set in WAMP is 2084KiB where as in MAMP is 32MiB.
If you even refer to the documentation from PHP in the FAQ_16 it talks about the max_upload_limit in php.ini.
Documentation.html#faq1_16
a very userful link is below:
http://www.magentocommerce.com/wiki/magento_filesystem_permissions
If you are using XAMPP in Ubuntu
Follow theses steps
/opt/lampp/etc/php.ini
Seach for the below line and change it according to your need.
; Maximum allowed size for uploaded files.
upload_max_filesize = 2M
In Ubuntu 18.04 apache2 does change the upload size on the below php.ini file :
root#xxxxxxxxxx:/etc/php/7.2/apache2# pwd
/etc/php/7.2/apache2
root#xxxxxx:/etc/php/7.2/apache2# vi php.ini
Open php.ini file
(Open xampp-control-panel. In front of Apache, there is a config button. Click on that and php.ini will be opened).
In php.ini there is
upload_max_filesize=2M
update it to
upload_max_filesize=10M
(you can update it as per your requirement)
After this, you have to restart apache in xampp-control-panel

Categories