首页 > 解决方案 > 单击删除按钮时如何从文件夹中删除图像

问题描述

这是我的代码

    echo"<tr>";
        echo "<td>". $row["item_name"]."</td>";
        echo "<td>". $row["description"]."</td>";
        echo '<td><img class="avatar" src="'.$row["imglink"].'"></td>';
        echo "<td>". $row["status"]."</td>";
        echo '<td><a href="studentinventoryedit.php?item_id='.$row['item_id'].'"><button title="edit" type="button" class="btn btn-default btn-sm"><span class="glyphicon glyphicon-pencil white"></span></button></a>
        <a href="deleteitem.php?item_id=' . $row["item_id"].'";><button name="delete" type="button"  class="btn btn-default btn-sr"  data-confirm="Are you sure to delete this item?"><span class="glyphicon glyphicon-trash white"></span></button></a>';

我的PHP代码

<?php
session_start();
require 'dbconfig/config.php';
$item_id = $_GET['item_id']; // $id is now defined
$query = "DELETE  from itemtbl where item_id='$item_id'";
$query_run = mysqli_query($con,$query);
$path = $_POST['imglink'];
            header("Location: studentinventory.php?"); //redirect to relevant page
?>

这是我的数据库的图片: 数据库

如果我单击删除,它将传递 id,并删除项目文件,但图像没有被删除。我试图用谷歌搜索如何从文件夹中删除图像,但没有这样做。

标签: phphtmlmysqldelete-file

解决方案


推荐阅读