413 Error on PHP Video Upload on Windows Server with IIS - php

The video upload works fine with a 23 MB file, for example, but when I try a 38 MB file (or anything larger than that), after about 10 or 15 seconds, it fails with a 413 error.
I've modified my php.ini with the following settings:
memory_limit = 5000M
upload_max_filesize = 500M
post_max_size = 500M
max_input_time = 60
I've confirmed by looking at phpinfo.php that these settings are in effect.
I've also gone into IIS and increased the uploadReadAheadSize from 49152 to 491520000 bytes, and restarted the server.
The machine itself is running Windows Server 2016 with 32 GB of RAM.
All of these settings appear to be sufficient to upload a 38 MB file and yet I'm running into this error which tells me there's something else I need to check or adjust. I realize there are similar threads, but I've tried all the suggested solutions and still it doesn't work, so I need a different solution.
EDIT: My form looks like this.
<form id='upload_video_form' enctype='multipart/form-data' style='height:0px;margin:0px'>
<input type='file' style='display:none' accept='video/*' name='upload_video_file' id='upload_video_file' />
<input type=hidden name=upload_video_companyid value=".$companyid.">
<input type=hidden name=upload_video_childid id=upload_video_childid value='".$childid."'>
<input type=hidden name=upload_video_reportid id=upload_video_reportid value='".$mediaid."'>
</form>

The Webserver might define something like "client_max_body_size" (nginx) or "LimitRequestBody" (Apache) below that size.
IIS setting, according to this article, is "maxAllowedContentLength"
https://www.inflectra.com/support/knowledgebase/kb306.aspx
PHP settings come only after the webserver...
hth

Related

Cannot upload file on Apache server

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.

php upload file error code 3

Upload bigger file( > 10KB) will get error code 3(UPLOAD_ERR_PARTIAL) in $_FILES['file']['error'] and small file( < 10KB) will upload successfully.
If the file exceed the limit php post_max_size or upload_max_filesize, it should get error code 1 UPLOAD_ERR_INI_SIZE. However, getting error code 3 UPLOAD_ERR_PARTIAL which is incorrect.
I guess it has something wrong with apache setting, and have no idea how to solve this problem.
Using below software and its versions
php 5.6.17
apache 2.4.18
Following is the php.ini:
post_max_size = 8M
file_uploads = On
upload_tmp_dir = "/tmp"
upload_max_filesize = 2M
and when upload larger file(hi.png) the error log in /var/log/httpd-error.log
PHP Notice: Missing mime boundary at the end of the data for file hi.png in Unknown on line 0
here are index.php
<!DOCTYPE html>
<html>
<body>
<form action='upload.php' method='post' enctype='multipart/form-data'>
Select image to upload:
<input type='file' name='fileToUpload' id='fileToUpload'>
<input type='submit' value='Upload Image' name='submit'>
</form>
</body>
</html>
and the upload.php
<?php
if($_FILES['fileToUpload']['error'] > 0){
echo "error code".$_FILES['fileToUpload']['error']."<br>";
}
else{
echo "file name:".$_FILES['fileToUpload']['name']."<br>";
echo "file type:".$_FILES['fileToUpload']['type']."<br>";
echo "file size:".$_FILES['fileToUpload']['size']."<br>";
echo "file path:".$_FILES['fileToUpload']['tmp_name']."<br>";
move_uploaded_file($_FILES['fileToUpload']['tmp_name'],"uploads/".$_FILES['fileToUpload']['name']);
}
?>
I had the same problem in a FreeBSD 10.1 jail with php 5.6.18 and apache 2.4.18: Files above 7950 bytes would constantly and consistently fail with error 3, no matter which limits were set.
After ages I finally isolated the issue: The PHP module (mod_php56) was compiled with apache2filter SAPI but enabled as a handler via AddHandler. The solution was to review the port options and rebuild mod_php56 with standard options (without AP2FILTER).
Long story: Check if you have port option OPTIONS_FILE_SET+=AP2FILTER (Apache 2 Filter SAPI) on, but PHP configured the usual way as a handler ( AddType application/x-httpd-php .php ). Removing the option (as the default build/port does), and rebuilding the mod_php56 package solved the problem for me.
To verify if this is your case too, you can echo the php_sapi_name(). if it is apache2filter but php is enabled via AddHandler directive, you have the same problem. After rebuild, your php_sapi_name() should be apache2handler. Both options are also checkable in phpinfo(), as "Apache 2.0 Filter" and "Apache 2.0 Handler" respectively.
Note that this does not explain why it actually broke uploads (or why the module worked with the Handler configuration in the first place).
You might also succeed by enabling mod_php as a filter instead as a handler, but I did not check that here.

Partial results are valid but processing is incomplete: mod_fcgid: can't get data from http client

I would like to upload large files up to 50GB.
I edited my php.ini
max_execution_time = 18000
max_input_time = 18000
post_max_size = 50G
upload_max_filesize = 50G
I increased mod_fcgid values in my vhost
IdleTimeout 18000
ProcessLifeTime 18000
FcgidMaxRequestLen 64424509440
FcgidIOTimeout 18000
I can upload files around 2-3GB maximum, but for more there are two cases:
No error in apache logs for files around 10GB
An error for files around 5GB : (70008)Partial results are valid but processing is incomplete: mod_fcgid: can't get data from http client
The site (if it can help you) : http://filetransfer.fr
Thank you in advance to any one who will help me !
Debian 7, apache 2.2.22, PHP 5.4.45
We got that only with Internet Explorer / Edge.
As long we use something different everything's OK.
It seems compressed content in IE / Edge is somehow buggy.
You may try to disable compression and check if that goes away.

PHP stops after exactly 46 seconds

I have seen many topics with a similar question, but not a similar situation, because the php settings do not seem to be the problem.
The current php.ini settings are:
max_execution_time = 600
max_input_time = 600
memory_limit = 512M
post_max_size = 192M
upload_max_filesize = 192M
These settings cannot be overwritten by the local .htaccess
The script
The script is PHP and does the following:
User uploads a movie file (using uploadify).
Once the upload is finished a script uses ffmpeg to convert it in to a lower quality 480p flv file.
The problem
This script has always worked and since the upgrade from php 5.3.9 to 5.3.17 it has stopped working.
The upload part works fine. I have tried it with 1Mb to 190mb files.
Once uploaded the conversion starts and the script always stops at exactly 46 seconds. I have no clue why, but it is always 46 seconds.
The server
The server is a xeon quad-core 16Gb ram and a load average of 0.62 (8 = 100% cpu usage)
I truly have no idea what the problem seems to be. The script worked fine and has not changed. So it must be something to do with the new PHP or perhaps Apache, but I have no clue.
Does anyone have a suggestion regarding what the problem could be?
Check the TimeOut settings for Apache, or add this in the VirtualHost section:
TimeOut 2400
You can also check if it really is a timeout or maybe an other problem (like memory) by making a script that sleeps for 47s:
<?php
sleep(47);
echo "Hi I'm still alive!";
Solution
Thanks to Nin, I found something in my apache error_log and was able to fix it:
Login to WHM > Apache Configuration > Include Editor > Post VirtualHost Include > All
and add
<IfModule mod_fcgid.c>
FcgidProcessLifeTime 8200
FcgidIOTimeout 8200
FcgidConnectTimeout 400
FcgidMaxRequestLen 1000000000
</IfModule>
It seems to be a fcgi problem.

PHP still won't allow file uploads larger than 2 MB

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

Categories