[英]php://input is empty for requests less than 10MB
Problem: 问题:
Raw POST requests lower than 10MB don't reach php://input buffer. 低于10MB的原始POST请求不会到达php:// input缓冲区。 I have no problem with requests over 10MB.
超过10MB的请求没有问题。
Anyone having a clue? 有人知道吗?
System: 系统:
OS: Ubuntu 16.04 操作系统:Ubuntu 16.04
Software: Apache with Nginx & PHP 7 软体:Apache with Nginx&PHP 7
Story: 故事:
I have used blueimp jQuery fileupload on one of my website. 我已经在我的网站之一上使用了blueimp jQuery fileupload 。 The files that I upload are large, over 1GB.
我上传的文件很大,超过1GB。 The upload script uploads in chunks of 10MB, but the last chunk never gets uploaded.
上载脚本以10MB的块上传,但最后一个块永远不会上传。 When I lowered the chunk size to 5MB, not even the first chunk gets uploaded.
当我将块大小减小到5MB时,甚至第一个块都没有被上传。
I have watched the upload in Firefox developer tools, the request is made and it's valid. 我已经在Firefox开发人员工具中观看了上传,该请求已发出且有效。
var abort_transfer = false;
$('#fileupload').fileupload({
url: 'my_url',
dataType: 'json',
maxChunkSize: 1000000,
add: function(e, data) {
data.submit();
},
send: function(e, data) {
$('button[type="submit"]').prop("disabled", true);
},
done: function(e, data) {
console.log('done', e, data);
$('button[type="submit"]').prop("disabled", false);
},
fail: function(e, data) {
console.log('fail', e, data);
},
chunksend: function(e, data) {
if (abort_transfer) return false;
},
chunkdone: function(e, data) {
if (data['jqXHR']['responseJSON']['status'] == 'nok') {
abort_transfer = true;
console.log('chunkdone', data['jqXHR']['responseJSON']);
}
},
progressall: function(e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress').css('width', progress + '%').text(progress + '%');
},
formData: function(form) {
return [
{name: 'action', value: 'upload-large-file'}
];
}
})
.prop('disabled', !$.support.fileInput);
I found the problem. 我发现了问题。
My PHP settings were: 我的PHP设置是:
upload_max_filesize 2M upload_max_filesize 2M
post_max_size 8M post_max_size 8M
TL & DR TL&DR
Something peculiar 奇特的东西
The blueimp jQuery fileupload sends the chunks in php//:input buffer, but the last chunk. blueimp jQuery fileupload在php //:input缓冲区中发送块,但最后一个块。 The last chunk is sent in $_POST .
最后一块在$ _POST中发送。
What I have changed 我改变了什么
I added code to handle the last chunk in $_POST: 我添加了代码来处理$ _POST中的最后一个块:
Because the $_POST chunk was bigger then the upload_max_filesize, it didn't arrived (gave error 1 in $_FILES['file']['error'] ). 因为$ _POST块比upload_max_filesize大,所以它没有到达(在$ _FILES ['file'] ['error']中给出错误1)。
I lowered the chunk size: 我降低了块大小:
$post_max_size = (int)ini_get('post_max_size') * (substr(ini_get('post_max_size'), -1) == 'M' ? pow(1024, 2) : pow(1024, 3));
$upload_max_filesize = (int)ini_get('upload_max_filesize') * (substr(ini_get('upload_max_filesize'), -1) == 'M' ? pow(1024, 2) : pow(1024, 3));
$chunk_size = min($post_max_size, $upload_max_filesize) - (10 * 1024);
Also, note that a chunk is higher then the set value because it contain the boundaries and post data. 另外,请注意,块比设置值高,因为它包含边界和后置数据。 So, the $chunk_size was lowered 10KB to be sure.
因此,可以肯定地将$ chunk_size降低了10KB。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.