亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用PHP刪除文件夾中的多個上傳圖像

如何使用PHP刪除文件夾中的多個上傳圖像

PHP
子衿沉夜 2023-05-26 17:47:54
如何在 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條經驗 獲得超6個贊

我有解決問題首先獲取數據庫中的所有值并使用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);

    }

}

謝謝 ...


查看完整回答
反對 回復 2023-05-26
  • 1 回答
  • 0 關注
  • 174 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號