I have a working html code where you can select multiple files and upload them via POST to a php script, here is the code:
<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>
The code works perfect when I open the html form on my local computer, I tried it with firefox. I can select and upload as many files as I want to.
As "multiple" is part of html5 IE8 for Windows XP does not work anyway, is this the same problem with my smartphone?
On my smartphone (Android 4.1.2) I just can select one file to be upload, the upload works well but why I am not able to select multiple files? I use the "build-in" browser from android, nothing special.
Can you tell me where I have to improve my code to be able to select multiple files on smartphones, or is it just not possible?
HTML Markup
<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>
This php code handles uploaded files and save to the server.
$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
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.