我正在使用HTML5多上传图片。我的代码与此类似
HTML
<input type="file" name="files[]" multiple="multiple" accept="image/*">
PHP
<?php
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
// Loop $_FILES to execute all files
foreach ($_FILES['files']['name'] as $f => $name) {
$extt = pathinfo($name, PATHINFO_EXTENSION);
$newname1 = rand(11111,99999);
$time22 = time();
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
$apt->query("INSERT INTO attachments VALUES ('', '$img', 'modules/news/attachments/$time22$newname1.$extt','0' ,'$name');");
if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$time22.$newname1.".".$extt)) {
$count++; // Number of successfully uploaded files
}
}
}
}
}
?>
我需要做的是在上传之前调整图像大小(客户端)。 如果有一个简单的例子适用于我的代码,将不胜感激。 我是HTML5的新手;(