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!
Related
I am trying to upload a file using uppy. On my server I am using php 8.0 and Apache 2.
I am uploading a file which is about 156Mb in size but server returns response with 413 status code and no message.
As per instruction given on all over internet I tried to configure my php.ini file and here are the updated configurations
post_max_size = 20480M
upload_max_filesize = 20480M
max_execution_time = 24000
max_input_time = 24000
memory_limit = 800M
Unfortunately above settings didn't help me. I have confirmed the php.ini file location with following command
php -i | grep Conf
Apart from this, I came across an answer that asked to set SecRequestBodyLimit value in modsecurity.conf. modsecurity was not even installed in my system but still I installed it and set the SecRequestBodyNoFilesLimit value as SecRequestBodyLimit 1000000000 but no luck.
I highly doubt that this is from server and Uppy has no role in this issue but I cannot predict the exact problem.
Response 413 is a typical error when you use ModSecurity, and the limit was set incorrectly. You should review the relevant documentation. If the size of your file is 156MB, you should calculate the base64 encoded size: multiply it with 4 and divide it by 3, so the approximate value is 208MB. I should set up 250MB for SecRequestBodyLimit, but not for SecRequestBodyNoFilesLimit - please keep it as low. 250MB is 262144000 byte, so try to set up this:
SecRequestBodyLimit 262144000
Also please check your Apache's error.log, you have to see every relevant information there.
How to increase transaction timeout? I want to upload videos, but large size of videos not uploaded?
It throws error The process *** exceeded the timeout of 60 seconds.
You need to change some settings in your php.ini:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must - sets the maximum time in seconds
Where your PHP.ini is located depends on your system environment. For more information: http://php.net/manual/en/ini.list.php
You should be able to do during runtime too using
set_time_limit(100);
http://php.net/manual/en/function.set-time-limit.php
or in your vhost-config
php_admin_value max_execution_time 10000
Having a global execution time limit that is LOW is mostly a good idea for performance-reasons on not-so-reliable applications. So you might want to only allow those scripts to run longer that absolutely have to.
p.s.: Dont forget about post_max_size and upload_max_filesize (like the first answer told allready)
To complete the answer of Hannes.
You need to change some setting in your php.ini:
upload_max_filesize = 2M
;or whatever size you want
max_execution_time = 60
; also, higher if you must
If someone want put in unlimited (I don't know why but if you want), you can set the time to 0:
You need to change some setting in your php.ini:
upload_max_filesize = 0
max_execution_time = 0
And if you don't know where is your php.ini. You can do a file "name.php" in your server and put:
<?php phpinfo(); ?>
And on your website, you can see the config of your php.ini and it's marked where is it.
Edit on 9 January 2015:
If you can't access your php.ini, you have two more options.
You can set this line directly in your "name.php" file but I don't find for upload_max_filesize for this option:
set_time_limit(0);
Or in ".htaccess"
php_value upload_max_filesize 0
php_value max_execution_time 0
if what you need to do is specific only for 1 or 2 pages i suggest to use set_time_limit so it did not affect the whole application.
set_time_limit(some_values);
but ofcourse these 2 values (post_max_size & upload_max_filesize) are subject to investigate.
you either can set it via ini_set function
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','2M');
or directly in php.ini file like response above by Hannes, or even set it iin .htaccess like below
php_value upload_max_filesize 2M
php_value post_max_size 20M
If you happen to be using Microsoft IIS server, in addition to the php.ini settings mentioned by others, you may need to increase the execution timeout settings for the PHP FastCGI application in the IIS Server Manager:
Step 1) Open the IIS Server Manager (usually under Server Manager in the Start Menu, then Tools / Internet Information Services (IIS) Manager).
Step 2) Click on the main connection (not specific to any particular domain).
Step 3) Under the IIS section, find FastCGI Settings (shown below).
Step 4) Therein, right-click the PHP application and select Edit....
Step 5) Check the timeouts (shown below).
In my case, the default timeouts here were 70 and 90 seconds; the former of which was causing a 500 Internal Server Error on PHP scripts that took longer than 70 seconds.
As an addition to above answers, you may use set_time_limit() function:
http://php.net/manual/en/function.set-time-limit.php
passing 0 as an argument will make your script run with no time limit.
If you cannot edit php.ini (on your server for example) you can attempt to change the php.ini parameters from within your php code. Try:
ini_set('max_execution_time', 'NUMBER OF SECONDS TO ALLOW BEFORE TIMEOUT');
If that doesn't work, try also setting 'set_time_limit' in the same way, beyond that I'd say your only option is to contact your host. These settings cannot be modified while in safe mode.
You had a typo: ini_set('max_input_time','200M') - value set needs to be an int, like ini_set('max_input_time','200')
I know you are specifically asking about the PHP timeout, but what no one else seems to have mentioned is that there can also be a timeout on the webserver and it can look very similar to the PHP timeout.
So if you have tried:
Increasing the timeout in php.ini by adding a line: max_execution_time = {number of seconds i.e. 60 for one minute}
Increasing the timeout in your script itself by adding: ini_set('max_execution_time','{number of seconds i.e. 60 for one minute}');
And you have checked with the phpinfo() function that max_execution_time has indeed be increased, then you might want to try adding this to .htaccess which will make sure Apache itself does not time out:
RewriteRule .* - [E=noabort:1]
RewriteRule .* - [E=noconntimeout:1]
More info here:
https://www.antropy.co.uk/blog/php-script-keeps-timing-out-despite-ini-set/
First check the php.ini file path by phpinfo(); and then changed PHP.INI params:
upload_max_filesize = 1000M
memory_limit = 1500M
post_max_size = 1500M
max_execution_time = 30
restarted Apache
set_time_limit(0); // safe_mode is off
ini_set('max_execution_time', 500); //500 seconds
Note: you can also use command to find php.ini in Linux
locate `php.ini`
Test if you are is safe mode - if not - set the time limit (Local Value) to what you want:
if(!ini_get('safe_mode')){
echo "safe mode off";
set_time_limit(180);// seconds
phpinfo();// see 'max_execution_time'
}
*You cannot set time limit this way if safe mode 'on'.
optional : if you set config about php.ini but still can't upload
-this is php function to check error code
$error_type = [];
$error_type[0] = "There is no error";
$error_type[1] = "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
$error_type[2] = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
$error_type[3] = "The uploaded file was only partially uploaded.";
$error_type[4] = "No file was uploaded.";
//$error_type["5"] = "";
$error_type[6] = "Missing a temporary folder. Introduced in PHP 5.0.3.";
$error_type[7] = "Failed to write file to disk. Introduced in PHP 5.1.0.";
$error_type[8] = "A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.";
//------------------------------
//--> show msg error.
$status_code = $_FILES["uploadfile"]["error"];
if($status_code != 0){
echo $error_type[$status_code];
exit;
}
You can also set a max execution time in your .htaccess file:
php_value max_execution_time 180
To really increase the time limit i prefer to first get the current value. set_time_limit is not always increasing the time limit. If the current value (e.g. from php.ini or formerly set) is higher than the value used in current call of set_time_limit, it will decrease the time limit!
So what's with a small helper like this?
/**
* #param int $seconds Time in seconds
* #return bool
*/
function increase_time_limit(int $seconds): bool
{
return set_time_limit(max(
ini_get('max_execution_time'), $seconds
));
}
// somewhere else in your code
increase_time_limit(180);
See also: Get max_execution_time in PHP script
I want to import a file(85 MB) at my local server.
I changed in the php.ini the following values of the three variables (upload_max_filesize, memory_limit and post_max_size) exactly as I saw at same problems, with the right order, I restarted my MAMP server and my laptop but it didn't change anything and I can't import files more than 2 MB.
Can you give any advise to fix it ?
You need to edit the php.ini file for the php version you are using. i.e. v7.2.1.
First check which version you're using by going to
MAMP-> Preferences -> PHP -> Select/Specify PHP Version
Then go to /Applications/MAMP/bin/php/php7.2.10/conf/php.ini and input the new settings there.
Stop your server and restart MAMP. Import should now run as expected.
Cheers.
Once you find out which version of PHP your MAMP is running, find the php.ini file at C:\MAMP\conf\php7.2.10\php.ini.
You'll need to change BOTH upload_max_filesize and post_max_size. If you only update the first, it'll default to the post_max_size.
Restart the MAMP and you should be good to go.
First check your PHP version
then according to your php version you have to go this php version file (php.ini)
and the change like below... :)
post_max_size = 256M
; Maximum allowed size for uploaded files.
upload_max_filesize = 256M
; Maximum execution time of each script, in seconds
max_execution_time = 600
; Maximum amount of time each script may spend parsing request data
max_input_time = 600
; Maximum amount of memory a script may consume (8MB)
memory_limit = 512M
I did all these things but nothing happened.I have two files with the name "php.ini",the first is "php.ini-development" and the second is "php.ini-production".Because i don't know which is the correct file to change the values,i changed the values and at the two because my phpinfo have like a Loaded Configuration File this:"C:\MAMP\conf\php7.0.13\php.ini" and not one of the two.
If you are seeing timeouts, you can increase max_execution_time and max_input_time.
I have a Debian Squeeze install on an Amazon EC2 instance running Apache2, and PHP 5.3.3-7. I would like it to be able to accept uploads from a standard point-and-shoot camera (about 5 MB). Accordingly, I've edited php.ini in /etc/php5/apache2/ to allow for up to 18MB uploads, and I've upped the time PHP will allow to work on a script.
Despite restarting Apache and even the machine itself, it absolutely refuses to upload any file larger than 2 MB. Is this an EC2 problem or is it still a PHP issue. I'm fairly sure I've ironed out all possibility of it being PHP, but I've been staring at the same 4 lines of code for the last week and searching like a mad person for what this could possibly be.
/etc/php5/apache2/php.ini:
max_execution_time = 120
...
max_input_time = 120
...
upload_max_filesize = 18M
...
post_max_size = 18M
I have double checked just now with phpinfo(), these settings are in effect, but it still does not work.
Check settings upload_max_filesize and post_max_size in your php.ini file
The problem is likely to be Sohusin. The default packages from APT on debian has Sohusin built in.
This also affects your upload size limit. Take a look at this link for a fix and an explanation:
http://www.cyberciti.biz/faq/linux-unix-apache-increase-php-upload-limit/
don't know if that will be of any help on your setup?
In Apache:
TimeOut
Amount of time the server will wait for certain events before failing a request
LimitRequestBody
Restricts the total size of the HTTP request body sent from the client
Also on some server setups you cant change php.inp via scipts
try this
max_execution_time = 120
max_input_time = 120
upload_max_filesize = 40M
post_max_size = 40M
Save then run
sudo service apache2 restart
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);
}