上传多个文件:max_file_uploads无效

时间:2016-10-29 04:05:47

标签: php apache codeigniter

我在max_file_uploads中将200设置为值php.ini,重新启动Apache并使用30个输入文件进行上传过程。以下是我的代码:

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    ... // Total quantity is 30
</form>

在我的控制器中,我使用var_dump来检测上传数据:

echo '<pre>';
print_r($_FILES['subavatar']['error']);
echo '</pre>';
die;

结果如下:

[error] => Array
    (
        [0] => 0
        [1] => 4
        [2] => 4
        [3] => 4
        [4] => 4
        [5] => 4
        [6] => 4
        [7] => 4
        [8] => 0
        [9] => 4
        [10] => 4
        [11] => 4
        [12] => 4
        [13] => 4
        [14] => 4
        [15] => 4
        [16] => 4
        [17] => 4
        [18] => 4
        [19] => 4
    )

仅收到20个文件,其中2个文件已上传到临时目录。

我错了什么?如何配置获取更多文件?
任何帮助的一杯啤酒:)
抱歉我的英语不好!

完整代码

档案controllers/Upload.php

class Upload extends CI_Controller {
    public function index() {
        if ($this->input->post()) {
            echo '<pre>';
            print_r($_FILES['subavatar']['error']);
            echo '</pre>';
            die;
        }
        $this->load->view('upload/index');
    }
}

档案views/upload/index.php

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
    <input type="file" name="subavatar[]" />
</form>

2 个答案:

答案 0 :(得分:0)

服务器将其限制为20.您可以尝试使用以下内容, 在php.ini中找到“max_file_uploads”并将其值更改为100

在max_file_uploads

下添加以下行

<强> suhosin.upload.max_uploads = 100

例如:

max_file_uploads = 100    
suhosin.upload.max_uploads=100

不太确定,因为它的工作原理和确切的解决方案,但你可以试试这个。

答案 1 :(得分:0)

在php.ini上将max_file_uploads设置为所需的文件数。

如果它不起作用:

  1. 确保您正在编辑正确的php.ini
  2. 您必须重新启动服务器
  3. 尝试在具有相同数量文件的max_file_uploads下添加suhosin.upload.max_uploads。