我为多个图像上传器制作了一个代码,但只是第一个图像存储到mysql表并且都存入路径,有些帮助吗?
这是我的代码:
if(!empty($_FILES['file'])){
foreach($_FILES['file']['name'] as $key => $name){
if($_FILES['file']['error'][$key] == 0){
$temp = $_FILES['file']['tmp_name'][$key];
$ext = explode('.', $name);
$ext = strtolower(end($ext));
$file = md5_file($temp) . time() . '.' . $ext;
if(in_array($ext, $allowed) === true && move_uploaded_file($temp, "product_images/{$file}") === true){
$path = 'product_images';
mysql_query("INSERT INTO `products` (img_path, img_name) VALUES ('$path', '$file')");
}else{
$errors[] = 'Format slike mora biti .jpg ili .png';
}
}
}
}