I configured PHP and lighttpd to take a maximum of 9MB a couple weeks back and it worked perfectly fine. I used the following lines:
php.ini: upload_max_filesize = 9000
lighttpd.conf: server.max-request-size = 9000
Now I need to support uploading files of up to 16MB. So, I changed the files to the following:
php.ini: upload_max_filesize = 16000
lighttpd.conf: server.max-request-size = 16000
It does not work properly. It is supposed to upload the files to /tmp/tmp in pieces, then reconstructs them into one in /tmp. The pieces go into /tmp/tmp but are never rebuilt, just deleted. Does anyone have any idea why?
You were probably assuming that the PHP config value is in kbytes. According to the PHP documentation for upload_max_filesize, it is in bytes.
See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize, which states:
upload_max_filesize - integer
The maximum size of an uploaded file. When an integer is used, the
value is measured in bytes.
Also refer to the PHP FAQ for other values that you can use for this and other config values:
http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes
Related
I tried to raise the upload_max_filesize value in the php.ini (mamp 2.1.2 with the PHP version 5.4.10). The Server runs on port 80. I found several anwsers here but no one really applies.
When I use the phpinfo () function to get the "Loaded Configuration File" I get the path: /Applications/MAMP/bin/php/php5.4.10/conf/php.ini, but the shown configuration form the phpinfo () don't match with the configuration in my php.ini.
In my php.ini stands upload_max_filesize = 100M the phpinfo () tells me 2M.
After I edited the ini I restared the server and my machine.
So why can't I change the upload_max_filesize?
Edite:
After setting the Port to 8888 the config file is loaded correctly. Maybe there is a conflict with the Apache-Server of the OS?!
This is because MAMP and MAMP PRO overwrites php.ini with a template file every time the services are started. Therefore, to make your desired php.ini changes, you need to change the template.
In my instance using MAMP PRO on OS X, that template was found within:
/Applications/MAMP PRO/MAMP PRO.app/Contents/Resources/
In this folder, you will find several php.ini versions for each version of PHP that is available to you. You will want to edit the .ini file for the PHP version you are running. In my case, that was php5.5.10.ini. After editing, restart your MAMP and your new settings should take effect.
Also you have to edit: post_max_size and memory_limit
post_max_size integer
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than
upload_max_filesize. If memory limit is enabled by your configure
script, memory_limit also affects file uploading. Generally speaking,
memory_limit should be larger than post_max_size. When an integer is
used, the value is measured in bytes. Shorthand notation, as described
in this FAQ, may also be used. If the size of post data is greater
than post_max_size, the $_POST and $_FILES superglobals are empty.
This can be tracked in various ways, e.g. by passing the $_GET
variable to the script processing the data, i.e. , and then checking if
$_GET['processed'] is set.
php ini core manual
Try editing /Applications/MAMP/bin/php/php5.4.10/conf/php.ini
and restart the server.
Or try to set it programmatically
ini_set('upload_max_filesize', '100M');
I have a really odd problem. I am using an upload form to upload videos. Sometimes I have to try twice to upload a file so I know it works but these files take a long time to upload so I don't want the end-user getting mad if the process fails. Also, this works 100% of the time on my test machine so I am thinking there is a config problem.
The file is 330mb and I set upload_max_filesize and post_max_size to 500mb. The max_execution_time and max_input_time are set to 60000 for testing purposes. memory_limit is what I think may be the problem. It is set to 128mb. Does it need to be higher to have a consistent upload success rate? Anybody know of any other problems that could cause things to go wrong?
You're right in assuming memory_limit is your culprit.
Taken from php.net.
post_max_size (int)
Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize.
If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size. When an integer is used, the value is measured in bytes. Shorthand notation, as described in this FAQ, may also be used. (...)
I am trying to modify existing PHP code, mySQL database and server settings (php.ini and .htaccess) at GoDaddy to allow for uploads in excess of 20MB (new limit will be 30M). Currently, when I upload anything larger than 8MB, the PHP code apparently executes (I know this because there is an update query that shows the result of the upload), no errors are reported from PHP, mySQL or the server, but nothing is uploaded either.
I have set the following parameters in the php.ini file:
memory_limit = 100M
post_max_size = 30M
file_uploads = On
upload_max_filesize = 30M
max_execution_time = 0
max_input_time = 0
my .htaccess file says
LimitRequestBody 0
My PHP code works well for files under 8 MB but I am having trouble figuring out why anything over that is not happening at all. I checked the file upload location (I physically upload the file to the server's filesystem before I insert/update the data into mySQL) and the files over 8MB never make it. So my guess is that this is where it fails.
Anyone have an idea what I am missing?
Thanks in advance for any input.
M
EDIT:
OK - feel free to award me the dufus badge! I am working in php5. The friggin php.ini file (at least on this server - don't know if this is true of other servers) only works for versions below 5. For version 5 you have to use php5.ini.
As per the GoDaddy support document: http://help.godaddy.com/article/1475
On MySQL side, there is max_allowed_packet variable that limits size of single request, e.g the size of SQL query. You can set it to 50MB or so in your case.
Use a phpinfo file to check for definite what the limits are. Just make a file with the following contents and call it whatever you like (with php extension...):
<?php phpinfo(); ?>
According to this post (http://wordpress.org/support/topic/upload_max_filesize-increase-on-godaddy) you need to add another line to your .htaccess:
suPHP_ConfigPath php.ini
Bottom-line:
Do I need to be concerned about setting post_max_filesize >> memory_limit?
Details:
This answer suggests that uploaded files do not need to fit within php’s memory_limit. The php docs suggest that the entire post should fit within php’s memory limit.
I find the docs surprising and I’m hoping someone can elaborate. For example take the following php configs:
; config A
memory_limit = 50M
upload_max_filesize = 100M
post_max_filesize = 1000M
max_file_uploads = 10
and
; config B
memory_limit = 50M
upload_max_filesize = 10M
post_max_filesize = 1000M
max_file_uploads = 100
With these configurations I’d expect to be able to:
upload 10x100mb files to server A, and 100x10mb files to server B. I would also expect that: Working with any one of the 10 files uploaded to server A is a problem (100Ms of file in a 50M bag…).Working with any 1 of the 100 files uploaded to server B is okay (10 < 50). While experimenting with less round but equivalently related numbers, I’ve found these expectations hold true.
This experience would lead me to say that "generally the memory_limit should be larger than the upload_max_filesize"; instead, the php docs say:
generally speaking, memory_limit should be larger than post_max_size.
Why and what happens if it isn't?
When my php code is executed I see no evidence that all of the posted files are in memory. It seems to me that all I’ve got is a $_FILES array of paths to files found exclusively on disk. Is php holding the whole post in memory at some point prior to my ability to introspect the environment? Do I need to be concerned about setting post_max_filesize >> memory_limit?
Aside:
Violating the manual's rule does not result in a grossly broken server (w/ php5.3 apache2.2 debian 6).
PHP will accept uploaded files that are individually smaller than upload_max_filesize and together take less than post_max_size bytes. The PHP documentation is wrong with regard to memory_limit which does not need to hold the file contents posted.
The following configuration works with both Apache2 module and CGI, and accepts files smaller than 1G.
upload_max_filesize = 1G
post_max_size = 1G
memory_limit = 32M
Do I need to be concerned about
setting post_max_filesize >>
memory_limit?
Only if you plan on reading an entire file into memory and the file that you read in is larger than the space you have allocated to PHP (i.e. memory_limit), in which case you'll run out of memory.
My own personal experience is that you HAVE to have a memory_limit higher than post_max_size and upload_max_size.
The post_max_size refers to the entirety of the POSTed data. This includes any form fields that may have been included with the file itself. The upload_max_size is the largest allowable size a file can be within that upload.
For instance. with a post_max_size of 10mb and a upload_max_size of 1mb, you could upload 9 files, each 1mb in size, Why 9 files? because part of the POST data is the file metadata - filename, mimetype, file size, etc... This all takes up some space, so your 9 files will actually take up 9.01megabytes or so. The 0.99 leftover is too small for another file, so you can't upload that 10th, even though it fits within the upload_max_size limit.
As for memory_limit, not only do you have to have enough "room" for the files that were uploaded, you have to remember that this limit applies to the script as a whole. A memory_limit of 10mb would allow for only a 9megabyte file to be uploaded, because PHP itself and all the associated code and libraries will suck up (say) 1 megabyte already.
Even though the files aren't held in memory - they get dumped out to temp files as soon as possible, they are passed in to PHP from Apache via STDIN. PHP has to read the files from that stream and copy them out to the temporary files you use in the ['tmp_name'] section of the $_FILES array.
For whatever reason, PHP seems to be basically doing "file_get_contents()" and slurping the files up in bulk, rather than doing a streaming-type copy. Hence requiring a memory_limit that exceeds the largest allowed file size.
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.
}