如何在 PHP 中删除多个图像。但单个产品删除工作正常。if (isset($_REQUEST['delete_product'])) { $ca_in_id = $_REQUEST['delete_product']; $where = array("ca_in_id" => $ca_in_id); $data = $this->select_where('catalog_inventory', $where); //$res = $data->fetch_object(); $result = $this->delete_where('catalog_inventory', $where); if ($result) { // (file_exists($pic1)) { // print_r($pic1); // exit(); while ($row = mysqli_fetch_array($data)) { $image = $row["upload_file"]; $pic1 = ("$image"); unlink('product_images/' . $pic1); print_r($pic1); } exit(); //} ?> <script> alert("Delete Sucess"); window.location = "list-product"; </script> <?php } else { ?> <script> alert("Delete Fails"); window.location = "list-product"; </script> <?php }}多个图像删除显示此错误:-如何解决这个问题?
1 回答
ibeautiful
TA贡献1993条经验 获得超5个赞
我有解决问题首先获取数据库中的所有值并使用explode函数使用count数据库列值并最终使用 for 循环。
这是我的代码:-
这段代码的意思是获取数据库中的值。
$data = $this->select_where('catalog_inventory', $where);
$res = $data->fetch_object();
$image = $res->upload_file;
$allimages = explode(",", $image);
$countallimages = count($allimages);
获得多个值和值后运行循环
for ($i = 0; $i < $countallimages; $i++) {
if (file_exists("product_images/" . $allimages[$i]) == false) {
echo "error ";
exit();
}
}
for ($i = 0; $i < $countallimages; $i++) {
$path = "product_images/" . $allimages[$i];
if (empty($path)) {
} else {
unlink($path);
}
}
谢谢 ...
- 1 回答
- 0 关注
- 142 浏览
添加回答
举报
0/150
提交
取消