我想上传多个文件上传。它与简单的 文件上传几乎类似,但我们需要做一些修改,使用html标记和 php代码。需要多个属性才能在html标记上添加。 Firefox,Chrome,Safari和IE 9+等主流网络浏览器都支持这个 属性。我要告诉你如何上传多个文件使用PHP 和基本HTML形式,但缺少点什么它(多个文件不 上传)用PHP多文件上传
我想下面的代码
HTML代码
<html>
<head>
<?php
if (isset($message)) {
foreach ($message as $msg) {
printf(“<p class=’status’>%s</p></ br>\n”, $msg);
}
}
# success message
if($count !=0){
printf(“<p class=’status’>%d files added successfully!</p>\n”, $count);
}
?>
<title>Multiple File upload 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脚本
<?php
$valid_formats = array(“jpg”, “png”, “gif”, “zip”, “bmp”);
$max_file_size = 1024*5000; //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
}
}
}
}
?>
究竟是什么问题? – Dekel