我需要通过浏览器一次上传很多图片(例如 200 张小图片)。我有这个代码:
<?php
if(isset($_POST['Upload_files']) and $_SERVER['REQUEST_METHOD'] == "POST"){
echo count($_FILES['files']['name']); // Even if I upload more than 20 files, it still displays 20.
$target_directory = "upload/";
foreach ($_FILES['files']['name'] as $file_number => $file_name) {
$file = $_FILES["files"]["tmp_name"][$file_number];
if (mime_content_type($file) != 'image/png' && mime_content_type($file) != 'image/jpeg')
{ $error[] = 'File '.$file_name.' is not in JPG / PNG format!'; continue; }
else
{ if(move_uploaded_file($file, $target_directory.$file_name)) {$count_of_upload_file++;}}
}
}
// If files were uploaded
if($count_of_upload_file != 0){echo 'Your files ('.$count_of_upload_file.' ) were successfully uploaded.';}
// If there was an error
if (isset($error)) {foreach ($error as $display_error) {echo '- '.$display_error.'<br />';}}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" multiple="multiple" accept="image/*">
<input type="submit" name="Upload_files" value="Upload files">
</form>
它有效。但是,我的提供商将“ max_file_uploads ”设置为 20(我无法更改它)。(Uploadify 扩展适用于 20 多个文件,但我想有自己的小解决方案。)所以我想我需要在这里添加一些东西,而不是一次上传 200 个文件,而是一个接一个地上传 200 个文件(或二十乘二十)。但我不知道该怎么做。(要使用 AJAX 吗?——我没用过,所以我真的不知道。)谢谢!