如何使用Codeigniter控制器仅验证5张图像上传到服务器。
答案 0 :(得分:0)
你应该使用像这样的简单count
函数
$count = count($_FILES['file']['size']);
foreach($_FILES as $key=>$value)//loop sample to get all images or files
对于验证图像和计数,您可以尝试此代码
$count=0;
$valid_types = array("image/jpg","image/png");
foreach ($_FILES['image'] as $file) {
count++;
if (!in_array($file['type'], $valid_types))
return 1;
return 0;
}
答案 1 :(得分:0)
你可以限制循环,但要确保你的图像是sequance。例如,
$fileCounts = sizeof($files['name']);
foreach ($files['name'] as $key => $image) {
$totalImageIndex = ($key+1);
if($totalImageIndex <= 5 ) {
// Image code here
} else {
continue; // It will be in loop but skip the image uploading
}
}