我需要通过浏览器一次上传大量图像(例如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? - 我从来没有使用它,所以我真的不知道。)谢谢!
答案是真的ajax。在网上查找一些例子。 –