在这里,我试图将多个图像插入数据库,但这段代码没有发生,我只将图像的名称插入数据库并将图像移动到特定路径。对于单张图片上传,它的工作,当我尝试上传多张图片时,它会出错。请建议我你的想法。向所有人提前谢谢。我是php的新手,只是想学习。
$img_name = $_FILES['banner']['name'];
$img_size = $_FILES['banner']['size'];
$img_temp = $_FILES['banner']['tmp_name'];
$pht_name = $_FILES['photos']['name'];
$pht_size = $_FILES['photos']['size'];
$pht_temp = $_FILES['photos']['tmp_name'];
$pht_name_a = $_FILES['photos_a']['name'];
$pht_size_a = $_FILES['photos_a']['size'];
$pht_temp_a = $_FILES['photos_a']['tmp_name'];
$pht_name_b = $_FILES['photos_b']['name'];
$pht_size_b = $_FILES['photos_b']['size'];
$pht_temp_b = $_FILES['photos_b']['tmp_name'];
include "_lib/_req/conn.php";
// section 1 (page contents)
$name = $pg_name . '_540x165_' . '.' . $img_ext;
$path = "_img\\gallery\\540x165\\";
$target_path = $path . $name;
if(move_uploaded_file($img_temp, $target_path)){
$insert = "INSERT INTO page_content (p_c_id, p_c_name, p_c_link, p_c_group, p_c_text, p_c_img, p_c_tag)
VALUES ('', '$pg_name', '$pg_link', '$pg_group', '$text', '$name', '$pg_tag')";
$query = mysql_query($insert);
}
else{ die(mysql_error()); }
$md5_6 = substr(md5(rand()),0,6);
$name_a = $pg_name . '_258x130_' . $md5_6 . '.' . $pht_ext;
$path_a = "_img\\gallery\\258x130\\";
$target_path_a = $path_a . $name_a;
if(move_uploaded_file($pht_temp, $target_path_a)){
$insert_a = "INSERT INTO page_photos (p_p_id, p_p_name, p_p_img)
VALUES ('', '$pg_name', '$name_a')";
$query_a = mysql_query($insert_a);
}
else{ die(mysql_error()); }
// page photo no.2
$md5_7 = substr(md5(rand()),0,7);
$name_b = $pg_name . '_258x130_' . $md5_7 . '.' . $pht_ext_a;
$path_b = "_img\\gallery\\258x130\\";
$target_path_b = $path_b . $name_b;
if(move_uploaded_file($pht_temp_a, $target_path_b)){
$insert_b = "INSERT INTO page_photos (p_p_id, p_p_name, p_p_img)
VALUES ('', '$pg_name', '$name_b')";
$query_b = mysql_query($insert_b);
}
else{ die(mysql_error()); }