duanmu2013 2016-07-26 18:05
浏览 38
已采纳

使用循环取消链接多个图像

I have a code that is supposed to delete image name from mysql table and the actual image from the server folder. The name deletes from database but the actual images are not deleting. Below is the code:

 $sql_queryy = "SELECT imImage FROM gimage WHERE imID = '$chkbxk'";
 $photoresultt = mysqli_query($connBiscup, $sql_queryy);
 //$row_album_images = mysqli_fetch_assoc($photoresultt);

 while ($row = mysqli_fetch_assoc($photoresultt)) { 

        unlink($target . $row[0]);
        unlink($targett . $row[0]);
 }

Any help please

this was the initial code.

for($i=0; $i<$N;$i++){

            $chkbxk = $_POST['checkbox'][$i];

            $sql_queryy = "SELECT imImage FROM gimage WHERE imID = '$chkbxk'";
            $photoresultt = mysqli_query($connBiscup, $sql_queryy);
            //$row_album_images = mysqli_fetch_all($photoresultt);
            foreach ($row_album_images as $row)
            {
                unlink($target . $row[0]);
                unlink($targett . $row[0]);
            }
}

but because of the mysqlnd issue, i changed to a while loop.

  • 写回答

1条回答 默认 最新

  • douzi0609 2016-07-26 18:25
    关注

    You need to change mysqli_fetch_assoc to mysqli_fetch_array

    mysqli_fetch_assoc will return associative array (i.e. ['imImage'=>'img1'])

    mysqli_fetch_array will return both associative and numeric array (i.e. [0=>'img1','imImage'=>'img1']).

    Otherwise you may rewrite loop body to use associative array.

    while ($row = mysqli_fetch_assoc($photoresultt)) { 
    
            unlink($target . $row['imImage']);
            unlink($targett . $row['imImage']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊