假设有 2 个不同名称的相同图像。我想上传这些图片并将它们放在不同的文件夹中。假设 img1.jpg & a-img1.jpg 是图像。现在 img1.jpg 将位于“files/images/”位置,而 a-img1.jpg 将位于“files/a-images/”位置。我已成功上传图片,但它只会转到一个目标文件夹。这是我的代码,
$upload_errors = 0;
$images= $_FILES['img'];
$img_id = get_new_image_id();
$image_ok = true;
$queries = array();
$allowed_exts = array('jpg', 'png', 'jpeg', 'gif');
foreach ($images['tmp_name'] as $key => $val ) {
$fileName = $images['name'][$key];
$fileSize = $images['size'][$key];
$fileSize = round($fileSize/1024);
$fileTemp = $images['tmp_name'][$key];
$path_parts = pathinfo($fileName);
$fileExt = $path_parts['extension'];
$fileExt = strtolower($fileExt);
if($fileSize > 2*1024){
$image_ok = false;
}
if(!in_array($fileExt, $allowed_exts)){
$image_ok = false;
}
if($image_ok){
$upload_link = "files/images/".$img_id.".".$fileExt;
$tupload_link = "files/a-images/".$img_id.".".$fileExt;
move_uploaded_file($fileTemp, $upload_link);
move_uploaded_file($fileTemp, $tupload_link);
$img_id++;
}else{
$upload_errors++;
}
有没有办法识别像“a-img1.jpg”这样的图像文件?我非常需要这个帮助。提前Tnx!