PHP - Maximum Total Upload Size? - php

I have a php web page with 15 fields. The user will use it to upload images. I tested this by uploading 15 jpg images, each about 2 M, without any problems. On the day I launch, I will be moving this web page to another Linux shared hosting environment (still not sure which). Are there some web hosting environments that limit the size of total uploads in one http request?

Yes. There are (as far as I can remember) three or so configuration settings which will affect upload size restrictions:
upload_max_filesize, which sets an upper limit on the size of uploaded files
post_max_size, which limits the total size of posted data, including file data
max_input_time, which restricts the length of time the script is allowed to process input data, including posted values
upload_max_filesize is a limit on each individual file; however, post_max_size is an upper limit on the entire request, which includes all the uploaded files.
Different hosting environments will have these values set differently, which may affect your abilities upon deployment.

The upload limits are set through php ini. You can try get them like so:
$post_max_size = ini_get('post_max_size');
$upload_max_filesize = ini_get('upload_max_filesize');

It's a setting in php.ini. You can look in the output of php info for the field labeled "upload_max_filesize". To get a php info page, create a php file with the following code:
<?php phpinfo(); ?>
This post at php.net gives you sample code to get that information, and the rest of the page is a treasure trove of php configuration options.

There are bunch of PHP settings limiting the upload process:
file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time
post_max_size
I'd suggest reading this page: http://www.radinks.com/upload/config.php
While it's true many of these don't limit upload size, they do put a cap on the upload process - e.g. if memory limit is too low, then you'll have problems uploading big files that need to stay in memory for a little period of time.

This would be unusual, but of course, check with whatever hosting company you choose. If there were a limit, it certainly would be higher than 30 MB.

the php.ini directive "post_max_size" should limit how much data you can send in a single POST. if you post 15 images in one post I'm pretty sure that is still considered one POST. So it might be good to check this value before going live.

If you are using nginx then make sure that you have the following:
server {
...
client_max_body_size 100M;
....
}

here:
max_execution_time
max_input_time
memory_limit
post_max_size
upload_max_filesize
max_file_uploads

I've seen the best solution here so far, and this is the code:
/**
* Returns the maximally uploadable file size in megabytes
*
* #return string
*/
function getMaxUploadSize()
{
$max_upload = (int)(ini_get('upload_max_filesize'));
$max_post = (int)(ini_get('post_max_size'));
$memory_limit = (int)(ini_get('memory_limit'));
return min($max_upload, $max_post, $memory_limit);
}

Related

Laravel: Input array returning only 995 values in post [duplicate]

Could it be that a POST request is limited to size? I have a large procedure I want to cache the output from. Basically I want to store a lare html-table in cache because of the growth a particulary project, the number of queries and thereby the responsetime is getting out of hand.
Now i'm sending the large output which is retrieved by an ajax-call, in another ajax-call (after the first one completes), but I only get a small piece of the data back. I think my ajaxfunction is correct because the stored output is always the same (in characters). But I'm missing about 90% of the output in the cache...
there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).
"Could it be that a POST request is limited to size?"
Yes, there is a PHP setting: post_max_size
I just ran into this problem myself and found that since PHP 5.3.9 there is a new setting available which restricts the total number of post variables (not just the size).
max_input_vars = 1000
This may have been the same issue you were running into if you were using a nightly or release candidate version of PHP at the time.
Look for these settings in your php.ini
; Maximum size of POST data that PHP will accept.
; http://php.net/post-max-size
post_max_size = 8M
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = 128M
post_max_size specifies the maximum size of a POST, and since it has to be contained in memory, memory limit has to be bigger. The memory, will have to contain the running program and all the heap variables, including the POST.
If you increase only post_max_size over or near to the memory limit and forget to increase memory_limit, the POST size will be limited to a lower value when the memory is exhausted.
In this example you can see the default settings.

PHP file upload size limits

I know this question has been asked before, but I've gone through all previously described options and I'm wondering if I'm missing an option. I'm trying upload a file through Apache/PHP that is greater than 2.000GB in size. Files smaller than that work fine.
The following php.ini variables are set, and I have restarted Apache to make sure they are in effect:
max_input_vars = 10000
post_max_size = 5000M
upload_max_filesize = 5000M
max_file_uploads = 1000
max_execution_time = 600
max_input_time = 600
memory_limit = 10000M
I am using a javascript uploader, with no filesize limits in the script, and a PHP page to receive the uploaded files, also with no limits in the script. When it fails, it only gives this error message in the javascript console in Chrome and IE: Failed to load resource: net::ERR_CONNECTION_RESET. There are file size limit checks in the javascript and PHP pages, but those errors are never displayed... so I'm thinking it is not even getting the chance to check the file size in either place.
In case anyone hits this 2.0GB limit, the fix for me was that PHP 5.4 did not support uploads greater than 2.0GB. This limit was changed in PHP 5.6: http://php.net/ChangeLog-5.php#5.6.0
Upgrading to PHP 7.0 worked for me!

Fatala Error in Php with DOM

I have html dom parser and php script to store the table data to mysql. Now I'm getting Fatal Error on line 18. Below is the code of line 18 and is for finding table from HTML Web Page. Also I had applied this script to so many same webpages of different sizes (in kb) and more content but same. Then I found that there is not any problem with the script as it works fine on less sized (like 100kb, 200kb) pages, while it not works with large sized pages having large data (like 800kb, 900kb). So I think there is limit in memory on my server. Please help me resolve this issue.
.......
foreach($html->find('table#GridView1') as $e){
.......
Maybe pastes the Error messages would give us more information to solve the problem...
Anyway, to extend the memory limit in php. All you need to do is edit your php.ini(which maybe in the dirctory /php5/ or /Windows/, it depends.)
Find the content
; Maximum amount of memory a script may consume (128MB)
; http://php.net/memory-limit
memory_limit = XXM
Change it to the size that satisfies your system. And restart your Apache server.
Open simple_html_dom.php, go to line 65, which has:
define('MAX_FILE_SIZE', 600000);
It's standard put at 600000 which is 600kb, so change it to your desired amount.
Source
Finally after trying so many ways and giving 10 hours to this question, I got the solution. First changed the max_file_size limit in html DOM as tald by #Koen Hoeijmakers. Then the must important factor which we must need to improve in dedicated server having centos 5 and kloxo panel is to change all limits in .htaccess.. as below:
php_value upload_max_filesize 2M
php_value max_execution_time 300
php_value max_input_time 600
php_value memory_limit 320M
php_value post_max_size 80M
and got out of this hell(Error!!). No matter, thanks for your suggestions.

PHP: Uploading large files fail

Im confused... I can't seem to upload files in the 2gb range. When i try using curl to send a 1.92gb file to my site (through an API), it doesn't report anything at all, its just blank. When i send a 1kb file, it reports back like it should.
When i try uploading via the upload form, it ends up freezing mid way, around 33%. Although im not sure if only the progress bar has froze or if the actual file upload it self has been suspended. I suspect that only the progress bar has froze because it still says data is being sent even though the progress bar freezes.
My php.ini (yes, its reflected by phpinfo as well):
register_globals = Off
magic_quotes_gpc = Off
post_max_size = 2047M
upload_max_filesize = 2047M
max_execution_time = 25200 ; Maximum execution time of each script, in seconds
max_input_time = 25200 ; Maximum amount of time each script may spend parsing request data
memory_limit = 2048M ; Maximum amount of memory a script may consume (16MB)
short_open_tag = On
My vps doesnt actually have 2gb of ram at its disposal, but does memory_limit really need to be set this high?
How should i go about testing this? I know 400mb files work, i haven't tested anything in between 400mb and 1.92gb
You will need a premium account to test up to 2gb, so here is one you can play with:
User: testreferral
Pass: 1234
http://filefx.com
I dont understand where this problem is arising.
Check for:
Memory limit. Try uploading files above and below the actual memory limit.
Time limit. Aren't your uploads take 7+ hours, are they?
The effective settings. Some setting might be overridden by server/etc settings.
PHP: mysql query skipped/ignored after large file uploads?
Mysql was timing out during the file upload. So the file wasn't showing up in the DB

24MB PHP file upload fails silently

I'm writing an app that accepts .mp4 uploads.
So I've a 24.3MB .mp4 that is posted to the server, but it fails silently.
The next smallest file I have is a 5.2MB .flv. It's not the file type of course, but file size.
I wonder if anybody could shed some light on this?
P.S. the relevant php.ini entries are as follows:
memory_limit = 256M
upload_max_filesize = 32M
Help!
You should also set post_max_size. Files are sent using HTTP POST.
I wonder if it's encoding-related. Base64 encoding = 33% greater size. 24.3 * 1.33 = 32.4 MB > 32 MB. Try a 23.9 MB file and see if that succeeds
Set error reporting level to E_ALL. Might give you some hint about what's going wrong.
post_max_size is a good idea, also you should check for timeouts. Since uploading larger files takes longer, the webserver might decide it's all taking too long and cancel the request. Check for maximum execution time in php.ini, also check whether there are other server-side time limits (I know of webervers where all tasks are killed after 30 secs. no matter what. An upload might easily take longer than that).
Have you considered using a Flash-Based uploader? This gives you more control over the upload process, and you can display a progress bar during upload (more user-friendly)

Categories