gpt4 book ai didi

php - 更新表中的图像,保留旧图像

转载 作者:行者123 更新时间:2023-11-30 01:04:18 25 4
gpt4 key购买 nike

我有 12 张图像,我想用表单更新/编辑它们。我选择更新一个或多个但不是全部,但将旧图像名称保留在数据库中。

我尝试了以下代码,但是当我更新一两个图像时,它不会保留旧图像,并且表字段为空。

foreach($_FILES['more_images']['name'] as $key => $post_image) {
$getOld_ImageName = mysql_query("SELECT `image` FROM `more_images` WHERE `car_id` = '$id' AND `key` = '$key'") or die(mysql_error());
$getOld_Image = mysql_fetch_array($getOld_ImageName);
$more_imageOld = $getOld_Image['image'];

if (isset($post_image)) {
$file_name = $_FILES['more_images']['name'][$key];
$file_tmp = $_FILES['more_images']['tmp_name'][$key];

if($file_name == $more_imageOld) {
$updateMore_Images = mysql_query("UPDATE `more_images` SET `image` = '$more_imageOld' WHERE `car_id` = '$id' AND `key` = '$key'") or die(mysql_error());
} else {
move_uploaded_file($file_tmp, "$uploaddir/$file_name");
$updateMore_Images = mysql_query("UPDATE `more_images` SET `image` = '$file_name' WHERE `car_id` = '$id' AND `key` = '$key'") or die(mysql_error());
}
} else {
if ($key == $getOld_Image['key']) {
$post_image = $more_imageOld;
$updateMore_Images = mysql_query("UPDATE `more_images` SET `image` = '$post_image' WHERE `car_id` = '$id' AND `key` = '$key'") or die(mysql_error());
}
}
}

$_FILE 返回新的图像名称,并在我保留的图像上显示空白。

0 = 
1 = 4061857_1_b.jpg
2 = 4061857_2_b.jpg
3 = 4061857_3_b.jpg
4 = 4061857_4_b.jpg
5 = 4061857_5_b.jpg
6 =
7 =
8 =
9 =
10 =
11 =

换句话说,我正在尝试更新表,并且每个 $key 都是空白,以保持表中先前的图像名称不变。

有什么建议吗?

最佳答案

我将 if (isset($post_image)) 更改为 if (!empty($post_image)) 并且成功了。

关于php - 更新表中的图像,保留旧图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19823736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com