使用html和php通过智能手机上传多个文件


Multiple file upload with smartphone using html and php

我有一个可工作的html代码,您可以在其中选择多个文件并通过POST将其上传到php脚本,下面是代码:

<form id="form_907007" class="appnitro" method="post" action="server/phpmailer.php" enctype="multipart/form-data">
<label class="description" for="File_upload">File_upload </label>
<div>
<input name="file[]" type="file" size="50" maxlength="100000" multiple>
</div> 

当我在本地计算机上打开html表单时,代码运行得很好,我用firefox尝试过。我可以选择并上传我想要的任意多的文件。

由于"多重"是用于Windows XP的html5 IE8的一部分,无论如何都不起作用,我的智能手机也有同样的问题吗?

在我的智能手机(Android 4.1.2)上,我只能选择一个文件上传,上传效果很好,但为什么我不能选择多个文件?我使用安卓的"内置"浏览器,没有什么特别的。

你能告诉我在哪里我必须改进我的代码才能在智能手机上选择多个文件吗?或者这是不可能的吗?

HTML标记
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Multiple File Ppload with PHP</title>
</head>
<body>
  <form action="" method="post" enctype="multipart/form-data">
    <input type="file" id="file" name="files[]" multiple="multiple" accept="image/*" />
  <input type="submit" value="Upload!" />
</form>
</body>
</html>

这个php代码处理上传的文件并保存到服务器。

$valid_formats = array("jpg", "png", "gif", "zip", "bmp");
$max_file_size = 1024*100; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to exeicute all files
    foreach ($_FILES['files']['name'] as $f => $name) {     
        if ($_FILES['files']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$f] == 0) {              
            if ($_FILES['files']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name))
                $count++; // Number of successfully uploaded file
            }
        }
    }
}