2

我正在处理输入type="file" multiple="multiple"和 PHP 上传循环。

<input name="data[]" id="file" type="file" multiple="multiple" class="txtinput2" />

上面是我的 HTML,下面是我的 PHP:

if(isset($_POST['action'])=='uploadfiles'){
$count_data=count($_FILES['data']) ;   ######### count the data #####

for($x=0;$x<$count_data;$x++)

当我回显count_data时,它给了我一个5的输出,但是当我选择28个文件时,它说在输入字段中选择了28个文件。multiple="multiple"唯一支持5个上传吗?

我检查了 PHP 信息,它说最大文件上传20,最大帖子大小8m和最大文件大小128m,我尝试上传的所有文件的总大小为1.94 megs

Array ( [name] => Array ( [0] => DSCF0960.jpg [1] => DSCF0961.jpg [2] => DSCF0963.jpg [3] => DSCF0964.jpg [4] => DSCF0966.jpg [5] => DSCF0967.jpg [6] => DSCF0968.jpg [7] => DSCF0969.jpg [8] => DSCF0970.jpg [9] => DSCF0971.jpg [10] => DSCF0972.jpg [11] => DSCF0973.jpg [12] => DSCF0974.jpg [13] => DSCF0975.jpg [14] => DSCF0976.jpg [15] => DSCF0977.jpg [16] => DSCF0978.jpg [17] => DSCF0979.jpg [18] => DSCF0980.jpg [19] => DSCF0981.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg [2] => image/jpeg [3] => image/jpeg [4] => image/jpeg [5] => image/jpeg [6] => image/jpeg [7] => image/jpeg [8] => image/jpeg [9] => image/jpeg [10] => image/jpeg [11] => image/jpeg [12] => image/jpeg [13] => image/jpeg [14] => image/jpeg [15] => image/jpeg [16] => image/jpeg [17] => image/jpeg [18] => image/jpeg [19] => image/jpeg ) [tmp_name] => Array ( [0] => /tmp/php4uI9g8 [1] => /tmp/phpVx5WrZ [2] => /tmp/php2DbRCQ [3] => /tmp/phpT2gSNH [4] => /tmp/phpPDlZYy [5] => /tmp/phpMzCcaq [6] => /tmp/phpRxkwlh [7] => /tmp/phpgoRWw8 [8] => /tmp/phpYlGsIZ [9] => /tmp/phpYBG1TQ [10] => /tmp/phpTQBD5H [11] => /tmp/phpQesphz [12] => /tmp/php5U4dtq [13] => /tmp/phpp2G5Eh [14] => /tmp/phpwaZZQ8 [15] => /tmp/php4W0W2Z [16] => /tmp/php7g3WeR [17] => /tmp/phpeZj0qI [18] => /tmp/phpAGo6Cz [19] => /tmp/phpbXlfPq ) [error] => Array ( [0] => 0 [1] => 0 [2] => 0 [3] => 0 [4] => 0 [5] => 0 [6] => 0 [7] => 0 [8] => 0 [9] => 0 [10] => 0 [11] => 0 [12] => 0 [13] => 0 [14] => 0 [15] => 0 [16] => 0 [17] => 0 [18] => 0 [19] => 0 ) [size] => Array ( [0] => 79605 [1] => 75839 [2] => 71245 [3] => 63228 [4] => 64201 [5] => 74440 [6] => 75350 [7] => 73367 [8] => 72491 [9] => 69725 [10] => 75508 [11] => 72755 [12] => 76076 [13] => 72140 [14] => 68745 [15] => 77859 [16] => 74281 [17] => 74613 [18] => 71702 [19] => 75916 ) ) 
4

1 回答 1

0

您的阵列中共有 20 个文件,分为 5 个子阵列,根据您在问题中所说的是您的上传限制。

我检查了 PHP 信息,它说最大文件上传 20

第一个数组是按顺序排列的每个文件的旧文件名。
第二个数组依次是每个文件的文件类型。
第三个数组是保存文件的位置及其临时名称。
第四个数组是如果任何文件上传失败,我假设它将是 0 或 1 为 0 没有错误。
最后一个数组是按顺序排列的每个文件的文件大小。

您使用以下方法计算所有文件:

$count_data=count($_FILES['data']['name']) -1;

并像这样阅读它:

for($i=0; $i < $count_data; $i++)
{
    if ($_FILES['data']['error'][$i] == 0)
    {
        $name = $_FILES['data']['name'][$i];
        $temp = $_FILES['data']['tmp_name'][$i];
        $type = $_FILES['data']['type'][$i];
        $size = $_FILES['data']['size'][$i];
    }
}
于 2013-07-10T01:03:22.933 回答