gpt4 book ai didi

javascript - 为什么 post_max_size 和/或 upload_max_filesize 限制被忽略?

转载 作者:行者123 更新时间:2023-11-28 06:35:24 25 4
gpt4 key购买 nike

我目前正在处理文件上传,并尝试不同的方法将更大的文件传输到我的服务器。

但是我发现this answer并且不明白为什么这会忽略 php.ini 的 post_max_size/upload_max_filesize。

我使用以下代码进行测试,该代码有效,但我不明白为什么 php.ini 似乎被忽略。

Javascript部分:

var reader = new FileReader();
reader.readAsArrayBuffer(file); // alternatively you can use readAsDataURL

reader.onloadend = function (evt)
{
// create XHR instance
xhr = new XMLHttpRequest();

// send the file through POST
xhr.open("POST", 'upload.php', true);

// make sure we have the sendAsBinary method on all browsers
XMLHttpRequest.prototype.mySendAsBinary = function (text)
{
var data = text;

if(typeof window.Blob == "function")
{
var blob = new Blob([data]);
}
else
{
var bb = new (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
bb.append(data);
var blob = bb.getBlob();
}
this.send(blob);
}

// start sending
xhr.mySendAsBinary(evt.target.result);
};

PHP部分:

// read contents from the input stream
$inputHandler = fopen('php://input', "r");
$buffer = fgets($inputHandler, 4096);

// do some stuff and keep reading with $buffer = fgets($inputHandler, 4096);

所以我的问题是:为什么我的 upload.php 会接收大小为几 GB 的文件,即使 post_max_size 限制为 8MB 并且 upload_max_filesize 限制为 2MB?

最佳答案

我相信 post_max_size 与允许的 POST 数据的最大数量有关,而 upload_max_filesize 是允许上传文件的最大大小?尝试检查您的 php.ini 文件以查看其中的值。

关于javascript - 为什么 post_max_size 和/或 upload_max_filesize 限制被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34337729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com