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.
Related
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
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!
The Issue
When uploading files of around 8MB or over, I recieve a 500 Internal Server Error.
All PHP settings in php.ini are correct
maxAllowedContentLength has been set in the web.config
Server Info
As one can probably tell from the maxAllowedContentLength, I am running IIS 7.5, with FastCGI and PHP 5.3.17
Additional Info
I have tried so many different things to get this working but simply cannot find the issue.
However, I have found the following bits of info that may help figure out the root of this problem:
When uploading files (larger ones) using the Media Wiki that I have on the server, I receive the same error, this goes to show that it is not an error in my code.
Most importantly - I managed to upload an 18MB file in the Plesk File Manager, this obviously means that Plesk was able to get around this config issue. I have tried to copy all of the Plesk Control Panel settings over to this domain in IIS but this does not seem to work.
The error is being returned before the script is executed, as I have tried writing exit; at the top to try to get a blank screen, but this is ignored and the 500 error is returned.
I think that the issue lies within the configure command part of the PHP configuration, because when I change the handler mapping of the .php files to use the Plesk php-cgi.exe instead of the usual one, I do not get the 500 Internal Error. Having said that, I cannot leave it on this PHP version as it is Plesk's own exe and there are other configuration issues.
The reason why I think it may be to do with the configure command, is simply because this differs hugely from one phpinfo() to the other.
If you have any ideas or suggestions, please post them. I have tried everything to my knowledge and cannot seem to fix this. If only it was Linux...
Thanks in advance
UPDATE 1
Forgot to add, there are no errors being returned in the PHP error log. As for IIS errors, I do not know where to look
UPDATE 2
This is what I have placed in my web.config file:
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483647" />
</requestFiltering>
</security>
UPDATE 3
With your help, we have managed to get the error displayed by IIS. This is what I am receiving:
PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit
of 8388608 bytes in Unknown on line 0
Is that to do with post_max_size?
UPDATE 4
PHP settings as follows (from phpinfo()):
post_max_size = 64M
memory_limit = 128M
max_file_uploads = 20
max_execution_time = 6000
upload_max_filesize = 64M
UPDATE 5
Lastly, just in case anybody can spot any potential issues, Plesk is able to upload large files absolutely fine, so I assumed that their php-cgi.exe was compiled differently. When I read a phpinfo() of their configuration the configure command information was very different:
My configuration:
cscript /nologo configure.js "--enable-snapshot-build"
"--disable-isapi" "--enable-debug-pack" "--without-mssql"
"--without-pdo-mssql" "--without-pi3web"
"--with-pdo-oci=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8=C:\php-sdk\oracle\instantclient10\sdk,shared"
"--with-oci8-11g=C:\php-sdk\oracle\instantclient11\sdk,shared"
"--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared"
"--with-mcrypt=static" "--disable-static-analyze"
Plesk's Configuration:
cscript /nologo configure.js "--enable-debug-pack" "--enable-cli"
"--enable-cgi" "--enable-isapi" "--enable-one-shot" "--enable-pdo"
"--enable-intl" "--with-openssl=shared" "--with-pdo-odbc"
"--with-iconv" "--with-xml" "--with-xsl" "--with-mysql"
"--with-mysqlnd" "--with-mysqli" "--with-pdo-sqlite"
"--with-pdo-mysql" "--with-curl=shared" "--enable-mbstring"
"--enable-mbregex" "--with-imap=shared" "--enable-sockets"
"--enable-shmop" "--enable-soap"
UPDATE (ANSWER)
This is extremely weird as the phpinfo() info is saying one thing, but it is obviously being ignored, not sure why.
If I change the post_max_size in Plesk, for that particular domain/sub-domain, then nothing is changed (although it appears to have changed in the phpinfo()). However, if I actually change the post_max_value in the php.ini then this fixes the issue.
The reason why this is not a good way to fix this, is simply because when Plesk updates, the php.ini is overwritten as PHP is updated and resultantly the changes made to the php.ini are lost. Which means that everytime that Plesk updates I will need to make changes tot he php.ini. This is why Plesk offers the ability to change PHP settings without making changes to the php.ini.
Can anybody think of why PHP is ignoring the local value and reverting to the value in the php.ini, even though the php.ini states that the local value is different?
If you look at the source code of PHP, you can see on the file php-5.4.8-src\main\rfc1867.c line 706-709 this:
if (SG(post_max_size) > 0 && SG(request_info).content_length > SG(post_max_size)) {
sapi_module.sapi_error(E_WARNING, "POST Content-Length of %ld bytes exceeds the limit of %ld bytes", SG(request_info).content_length, SG(post_max_size));
return;
}
Same is there also in file php-5.4.8-src\main\SAPI.c.
So, the message PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes in Unknown on line 0 is about post_max_size setting. You have confirmed from using phpinfo() that you have this setting configured correctly, but it seems to be using the default value of 8M anyway.
As to why, see this thread:
As it turns out, on Windows, you can only set ini directives that are
marked PHP_INI_USER per directory. Unfortunately,
upload_max_filesize and post_max_size are both PHP_INI_PERDIR.
From the PHP docs at
http://php.net/manual/en/configuration.changes.php
The settings for the directory would be active for any script running from this directory or any subdirectory of it. The values
under the key should have the name of the PHP configuration directive
and the string value. PHP constants in the values are not parsed.
However, only configuration values changeable in PHP_INI_USER can be set this way, PHP_INI_PERDIR values can not.
So even though Plesk has an interface to change those directives, and
even though phpinfo() picks up on them, they do nothing to change
the actual max upload sizes. Plesk should not allow you to change
those on Windows, and phpinfo() should not report the change, but
what can you do.
So, it's post_max_size, and it needs to be set on php.ini. Plesk setting simply will not work, even though phpinfo says otherwise. I also opened a bug entry on phpinfo behaviour as there didn't seem to be an entry for it.
This is a fairly common error and is due to the fact that the size of data being uploaded does not match file size: even if you POST max size is not exceeded by the file size, it could be by the uploaded data size.
See this page in the PHP manual.
; Maximum size of POST data that PHP will accept.
post_max_size = 8M
Another source of troubles (for VERY large texts) is UTF8 encoding. You might find yourself with a "six megabytes" TEXTAREA that is actually 6 mega*characters*, and with international codepoints it might run to, say, 8.2 megabytes. Thus you get an apparently contradictory situation of "six megabytes data exceed the configured 8 megabytes limit".
Update
You report two apparently contradictory facts:
PHP settings as follows (from phpinfo()):
post_max_size = 64M
and
PHP Warning: POST Content-Length of 12221448 bytes exceeds the limit of 8388608 bytes
It is clear from the PHPINFO that the limit for POST is 64M. Yet the error says that the limit is 8M (the default). So it seems to me that your code is talking to two different PHP implementations (Two different virtual hosts? A CGI version and a non-CGI version in the same host? Two different machines?)
IIS will re-use the FastCGI processes. You will need to kill off any old processes to get php.ini to reload.
Edit the FastCGI module and edit 'monitor changes to file' and select the php.ini file. This will force the child processes to restart whenever you save an edit.
You could turn the limits to -1, that way, you won't ever have troubles about the size of the files.
It is probably no the best solution as you are basically saying "if I don't see it, it doesn't exist", but believe, it's really reliable and will always work.
When I try to upload an image over about 4mb, then $_FILES['upload']['error'] returns 1 and the file wont upload. But in my php.ini I have upload_max_filesize set to 20mb....
Why am i getting an error?
Heres php code to check for error
if ($_FILES['upload']['error']) {
array_push($not_uploaded, $_FILES['upload']['name']);
if ($_FILES['upload']['error'] == 1) {
trigger_error('Iimage exceeded server php upload limit', E_USER_WARNING);
array_push($error_msgs, elgg_echo('services:image_mem'));
} else {
array_push($error_msgs, elgg_echo('services:unk_error'));
}
}
You should also check the configuration of the variable post_max_size in the php.ini file.
In PHP docs: Common Pitfalls
If post_max_size is set too small, large files cannot be uploaded.
Make sure you set post_max_size large enough.
As the php docs say, you need to send a (most often hidden) field with the name MAX_FILE_SIZE before the actual file. While theoretically even 4MB shouldn't work without it, this might be some hardcoded default.
Use the example form of the mentioned PHP docs page as a starting point.
I've been banging my head against this for 20+ hours now I would really appreciate some help!
I have simplified the problem here so the code is very simple. Basically this upload script works perfectly until I try to upload a file bigger than 25MB then it fails. PHP gives no errors.
index.htm
<form enctype="multipart/form-data" action="upload.php" method="POST">
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
upload.php
<?php
$target_path = "uploaded/";
$target_path = $target_path.basename( $_FILES['uploadedfile']['name']);
/***/highlight_string(print_r($_FILES, true)); //check array
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
}
?>
php.ini
[PHP]
post_max_size = 32M
upload_max_filesize = 32M
My host informed me that the upload limit on the server is 32MB. Ran phpinfo() & the variables in the ini are being changed. It is not a timeout issue (ran a 16mb upload when downloading a file - it took several minutes longer than the 25MB upload but still worked).
I have been spittin out the $_Files array as a string for error checking, heres what I get when it fails:
Array
(
[uploadedfile] => Array
(
[name] => 30.tif
[type] =>
[tmp_name] =>
[error] => 7
[size] => 0
)
)
There was an error uploading the file, please try again!
Any ideas? Tried it on different servers with the same problem.
According to this, it failed to write files to disk. Can you check quota/disk space/etc.?
memory_limit might also restrict the size of uploadable files.
Your error don't is for the size, the error code 7 is because the file "can't be save in the disk."
to more errors read: Upload code errors
Try change the directive "upload_tmp_dir" in php.ini file and check if is allow the upload of file: 'file_uploads = On'.
Thanks everybody, I'm sure now that it is a host problem, not a problem on my end - even though I've tried it on several hosts - I think it's pretty common for http post to be limited to around 25MB.
I have now set my uploader to take a maximum file size of 20MB, that should make it pretty safe on most hosts.