所以我有一个正在运行的脚本,它将脚本上传到正确的目录(由我创建),然后将图像放入该目录并重命名它们,太酷了!但是,我放置的少量显示错误文本始终会打印每个错误。因此,例如,我有$ j ++,并且由于我的错误,最大值将为$ j = 4,如果$ j = 4,则所有错误都会打印出来,并且您会认为有问题并且图像没有已上传。但是我选择了4张图像,其中3张已上传,但所有错误仍然显示。
所以我的问题是,为什么地球上会显示所有错误,为什么只上传4个图像中的3个?我希望能够一次上传30张图片...
代码
//Image Upload Section
$j = 0; //Variable for indexing uploaded image
$target_path = $imagePath."/"; //Declaring Path for uploaded images
for ($i = 0; $i < count($_FILES['file']['name']); $i++) { //loop to get individual element from the array
$validextensions = array("jpeg", "jpg", "png"); //Extensions which are allowed
$ext = explode('.', basename($_FILES['file']['name'][$i])); //explode file name from dot(.)
$file_extension = end($ext); //store extensions in the variable
$target_path = $target_path.md5(uniqid()).
".".$ext[count($ext) - 1]; //set the target path with a new name of image
$j = $j + 1; //increment the number of uploaded images according to the files in array
if (($_FILES["file"]["size"][$i] < 100000000) //Approx. 100000kb files can be uploaded.
&& in_array($file_extension, $validextensions)) {
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) { //if file moved to uploads folder
echo $j.
').<span id="noerror">Image Uploaded Successfully!.</span><br/><br/>';
} else { //if file was not moved.
echo $j.
').<span id="error">Please Try Again!.</span><br/><br/>';
}
} else { //if file size and file type was incorrect.
echo $j.
').<span id="error">***Invalid File Size or Type***</span><br/><br/>';
}
}
//End Image Upload Section
图片 Image of all the errors (After 3 out of 4 Images Uploaded Successfully
PS 附带说明一下,是否有一种简单的方法可以遍历目录并选择其中的所有图像,然后将它们显示为HTML?