php file size limit - php

I trying to use PHP's file upload abilities, but when I try to upload certain file sizes (9MB for example) it's not going through. Smaller files goes fine.
Even when I set error reporting to be on "E_ALL" and try and upload a bigger file. I don't see any error message.
I have tried setting these lines at the top of the PHP script that uploads the files but still no go:
ini_set('memory_limit', '96M');
ini_set('post_max_size', '96M');
ini_set('upload_max_filesize', '96M');

Take a look at the list of parameters for PHP and where you can set them. If I read that list correctly, post_max_size and upload_max_filesize can only be set in php.ini, not via ini_set.
Set those values in the appropriate php.ini (there are different ones for CLI and mod_php), or if you don't have access to the main php.ini create a php.ini in your folder.
To check if the settings work, create a phpinfo file and check the values.

try changing the php.ini file which is having certain properties.
you can change all the properties that u have mentioned in your php file into your ini file this worked for me. Try if it works for u as well

Try setting a MAX_FILE_SIZE entry in the form.
<input type="hidden" name="MAX_FILE_SIZE" value="100663296" />
where the number is in bytes. Additionally, try changing the PHP settings in either php.ini or a .htaccess file in the same directory. The syntax for php settings in htaccess files are:
php_value name value
So you would say:
php_value memory_limit 96M
php_value post_max_size 96M
php_value upload_max_filesize 96M
Also, are you using your own server, or some online host. Some online hosts set a maximum file upload limit that you have to change in the Control Panel (depending on what interface the host uses), or they just plain don't let you change the max file size.

I don't see any error message.
that's because file uploads has it's own error messages. check $_FILES['filename']['error']
I have tried setting these lines
but you didn't check if it has any effect! run phpinfo() to see actual values

Related

Why can I not upload files greater than 2MB? Php.ini has already been edited

I'm having the same problem this guy says he had: PHP still won't allow file uploads larger than 2 MB, although apparently he solved it.
I, however, cannot find a solution. I've edited the php.ini file to the following values:
upload_max_filesize = 20M
post_max_size = 20M
I've even tried raising them to 200M, but it still limits it at 2M, according to phpinfo().
Here are some of the variables per php.ini (name, local value, master value):
file_uploads On On
max_file_uploads 20 20
upload_max_filesize 2M 2M
I've restarted everything. The original value when I checked php.ini for upload_max_filesize was 10M anyway. It will upload smaller files, just nothing above 2MB.
Assicure that you have saved your php.ini.
Restart your webserver for example the service of Apache2 if you use it
Print again a page with phpinfo() and assicure that value has changed if not you haven't wrong file to edit.
Assure that html has attribute MAX_FILE_SIZE
Another way is to change in PHP this setting like:
ini_set('post_max_size', '20M');
ini_set('upload_max_filesize', '20M');
It is possible the file size limit is being overwritten in an .htaccess file, or in your PHP application, through ini_set() calls.
I will also remind you that when you change those values in php.ini, you probably need to restart Apache.
If this isn't something your webhost will let you do, you could always use ini_set() calls yourself, in your script. For example, place this near the top of your script:
ini_set('post_max_size', '64M');
ini_set('upload_max_filesize', '64M');
I've had this issue before. If you are running certain versions of web servers, such as running php-fpm with nginx, your php.ini file won't be in the place you expect it. For example, I believe php-fpm doesn't follow the normal php.ini, but rather a www.conf located in it's conf.d directory.
Anyway, check and make sure that your configuration isn't being overridden by a separate php.ini or other config file. If you cannot fix it in this way, you may have luck doing what Richard and Alessandro suggest.
I ran into a similar problem. the setting post_max_size was set to 3M.
I fixed it in the php.ini file from the /wamp/apache/bin folder.
I Hope it helps.
Always ensure that it is the correct php.ini file that you are updating its values.
I spent 2 weeks reconfiguring IIS7 only to realize that there were 2 php.ini files on was in the C:\Program Files (x86)\PHP\v5.4 and the other was in C:\php... however the one that worked was: C:\Program Files (x86)\PHP\v5.4
To ensure that you are on the correct path to the php.ini file
create a phpinfo.php file (structure of file below)
phpinfo();
call the file in the browser like: http://servername/websitename/phpinfo.php
Check the lline shown in pic below to verify that you are indeed editing the correct php.ini file.
Hope this helps cause it helped me. PS. Don't forget to make the changes mentioned above to increase the upload size limit
I also had the same problem and also I did the same changes in the ini.php file
upload_max_filesize = 200M
post_max_size = 200M
But it doesn't solve my problem. So, I went to wamp server in the taskbar (where we can see the green 'W' sign) and left clicked on it
PHP > PHP SETTINGS > upload_max_filesize = 256M (as the changes i made in ini.php were actually not made).
Then it WORKED.
Flogvit pretty much answered my question. WAMP was using a different php.ini file than was listed in the WAMP PHP settings option. I looked at the wamp configuration file and it was just "php.ini." I changed it to the full path of the php.ini file I wanted to use (there was another in the IIS folder), I restarted it and nothing happened. However, after restarting the computer, it now works. For some reason ini_set() doesn't work, however the solution is this:
1) open wampmanager.conf
2) change "phpConfFile = " from php.ini to the full path of the php.ini file you'd like to use, putting it in double quotes.
3) restart the computer that WAMP is on.
Thanks again for the help. That was a pretty weird problem and I don't know why I couldn't just restart WAMP (which runs all the servers, including the Apache server). I'm guessing there was something running outside of WAMP that was being run by WAMP, which is a bit of a mystery to me.
That's because you are editing the wrong config file. Check where your config file is being loaded from and edit that one instead. You might be editing the one located at /etc/php/[version]/cli/php.ini.
In my case, my loaded config file is at /etc/php/7.3/apache2/php.ini

What is the MAXIMUM file upload size in PHP ini file

I have changed the upload_max_filesize to 150MB in the php.ini file.
but http://localhost/info.php shows the upload_max_filesize is still showing 16MB .
I have also restarted the server.
what is the the problem?
I am unable to find the solution.
Make sure that post_max_size is larger than your upload_max_filesize value.
This limits the overall size of the POST body, which also has a bearing on the max upload size.
You will also need to ensure that memory_limit is larger than post_max_size.
Also upload_max_filesize should be changed in both php.ini files..
In the Apache folder, and the PHP folder..
Locate the php.ini file inside the wp-admin directory (if you can’t find this file see notes below)
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”)
You may also want to increase your max post size. Look for this line in your php.ini file “post_max_size” and increase it as well.
Save the changes to the file inside your wp-admin directory.
Try the upload again
If you still have issues, look for this file in your root directory and make the same changes.
move your php folder insise your localhost directory, open php.ini
press control + f find upload_max_filesize change it from 2M to whatever you want, and also change post_max_size from 8M to again whatever u want,save changes , overwrite this php.ini file with file in php folder,restart your localhost and check it.

PHP ini file and session deletion

Posted a question about an error I was getting the over day about Memory exceed when handling an image resize.
Managed to solve the problem with a local php.ini file and setting
[PHP]
upload_max_filesize = 5M
post_max_size = 5M
memory_limit = 64M
Now I realised I have a whole new problem :)
If I access a php file in the directoy with my custom local php.ini, it will override the original and
remove all my $_SESSION's
If I remove the local php.ini, it doesnt remove my sessions but then the image resize gives me a memory limit exceed error.
Any ideas? Can i set a php.ini (local) to just override the 3 parameters I want?
Thanks in advance,
P.s. tried setting it through CPANEL on tweak php.ini but those values seemed to be ignored.
Result
Had to contact tech support and they had to manually update my ini files.
If you have full control over your server, on most linux distros there is a conf.d directory which is loaded after all of the default php configuration, so you can override things. On ubuntu for example, that is /etc/php5/conf.d/, there you can create a file 'my.ini' (name doesn't matter as long as it ends in .ini) which will be automatically included.
If you don't have access to the entire server, there are several ways of altering those without overwriting everything:
Add the php configuration to .htaccess (if using Apache)
Set those options using ini_set('option', 'value'); in your php script
If you're going for the .htaccess route, here is an example, just append to end of your .htaccess file:
php_value upload_max_filesize 5M
php_value post_max_size 5M
php_value memory_limit 64M

how to dynamically change the max upload file limit in php?

I want to change the max upload file limit dynamically. means by not changing the php.ini file on server.
Whenever user had uploaded more then 2 mb then my upload limit should be change.
I want to do all this through php.
Thanks in advance.
The limits enforces by upload_max_filesize are enforced before the php script is run, so the setting cannot be changed dynamically with ini_set.
For more information on the file upload ini settings and where they can be changed, see:
- http://php.net/manual/en/ini.core.php#ini.sect.file-uploads
- http://php.net/manual/en/configuration.changes.modes.php
Assuming by "user" you mean a visitor to your site, there are really only two methods you can enforce such a limit without the file reaching its final destination:
1) Before the upload has occurred: On the client side. You could definitely do this using a java-based uploader. Whether you can get the filesize of the selected file using javascript, I don't know.
2) After the file is uploaded to the server, but before you move it to the final destination (before you run move_uploaded_file)
Try this:
ini_set('upload_max_filesize', your_value_here);
Make sure also that you have specified the correct acceptable settings for:
file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time
post_max_size
If you can't modify your php.ini, you might be able to do it with a .htaccess file:
php_value upload_max_filesize 50M
php_value post_max_size 50M

image upload in PHP

I can upload small size files with no problem,
but fail when the size is more than 1M.
What's the matter?
You probably need to configure the upload_max_filesize directive, in your php.ini file : PHP will not accept an upload of a file that is bigger than what this directive defines.
And note that you might also need to adjust post_max_size -- which defines the total size of data that can be POSTed (And files upload are sent via POST).
You can also take a look at the Handling file uploads section of the manual, which can give you a couple of useful informations about files upload.
Are you sure you have upload_max_filesize set correctly in php.ini?
Edit you php.ini file to allow for larger uploads.
HERE's some info
You can call echo phpinfo() and then verify your upload_max_filesize and other php environment settings. Its very possible that your script is dying because one of the max limits is being exceeded.
Depending on your environment you can either use ini_set() to change the necessary values at run-time or you can simply edit your php.ini file to set the value permanently. Please note that not all php.ini settings can be changed at run time and if you do edit php.ini, you will need to restart Apache.
As said by others check your php.in for upload_max_filesize and post_max_size settings. If they are okay and if you are using a 3rd party script for uploading, make sure the script is not limiting the max file size by doing something like:
if( $_FILES["file"]["size"] > (1024 * 1024) ) // disallow uploads > 1MB
{
// max size exceeded.
}

Categories