【问题标题】:Why is post_max_size and/or upload_max_filesize limitation ignored?为什么忽略 post_max_size 和/或 upload_max_filesize 限制?
【发布时间】:2016-03-24 02:33:46
【问题描述】:

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

但是我找到了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);

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

【问题讨论】:

    标签: javascript php upload


    【解决方案1】:

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

    【讨论】:

    • upload_max_filesize = 2M 和 post_max_size = 8M
    • @Nitro.de 你有问题写了post_max_size is limited to 2MB? 所以也许决定你的 post_max_size 值是多少
    • @robert 修复了 php.ini 的错误行^^
    • @Nitro.de - 如果您正在运行 Apache,我知道有一种方法可以在 .htaccess 文件中同时设置 upload_max_filesizepost_max_size?可能值得研究一下?不幸的是,我对 Apache 的了解有限,因为我是一个 Nginx 人......
    • @samuidavid 我会看看它。顺便说一句,我正在运行 Apache 是的
    猜你喜欢
    • 1970-01-01
    • 2011-12-06
    • 2010-11-22
    • 2013-06-29
    • 2012-10-27
    • 2020-03-11
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    相关资源
    最近更新 更多