我正在尝试设置一个多图像上传器,每当我尝试上传超过 20 个文件时,只会上传前 20 个文件。
在我继续之前,我只想说 php.ini 中的 max_file_uploads 设置为 400,因此非常相似问题的其他答案似乎无法解决我的问题。
我的完整代码如下,请注意我知道我正在使用 mysql_query,但这仅用于本地测试目的。
-
PHP
if(isset($_POST['upload'])){
include("SimpleImage.php");
echo count($_FILES['file']['name']);
for($i=0; $i<count($_FILES['file']['name']); $i++) {
$allowedExts = array("gif", "jpeg", "jpg", "png", "JPG");
$extension = end(explode(".", $_FILES["file"]["name"][$i]));
date_default_timezone_set('Europe/London');
$date = date_create();
if ((($_FILES["file"]["type"][$i] == "image/gif")
|| ($_FILES["file"]["type"][$i] == "image/jpeg")
|| ($_FILES["file"]["type"][$i] == "image/jpg")
|| ($_FILES["file"]["type"][$i] == "image/png"))
&& ($_FILES["file"]["size"][$i] < 10485760)
&& in_array($extension, $allowedExts)){
$name = date_timestamp_get($date) . "_" . mt_rand() . "." . $extension;
if ($_FILES["file"]["error"][$key] > 0){
$messages[] = "Return Code: " . $_FILES["file"]["error"][$i] . "<br>";
}else{
$imagethumbTrueLocation = "../../gallery/thumb/" . $name;
$imagelargeTrueLocation = "../../gallery/photos/" . $name;
$imagethumb = new SimpleImage();
$imagethumb->load($_FILES["file"]["tmp_name"][$i]);
$imagethumb->resizeToWidth(230);
$imagethumb->save($imagethumbTrueLocation);
$imagethumblocation = "thumb/" . $name;
$imagelarge = new SimpleImage();
$imagelarge->load($_FILES["file"]["tmp_name"][$i]);
$imagelarge->resizeToWidth(800);
$imagelarge->save($imagelargeTrueLocation);
$imagelargelocation = "photos/" . $name;
$queryresult = mysql_query("INSERT INTO gallery (thumbnail, highres) VALUES ('$imagethumblocation', '$imagelargelocation')") or die(mysql_error());
if(!$queryresult) {
$messages[] = "Failed to insert record into the database.";
}else{
$messages[] = "Record sucessfully added to the database.";
}
}
}else{
$messages[] = "Invalid file";
}
}
}
HTML
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="file[]" id="file" multiple>
<input type="submit" name="upload" value="Upload" />
</form>