管理者がデータベースから行を削除できるページがある管理パネルがあります。削除できる各行には、サーバー上のディレクトリに保存されている関連付けられたイメージがあります。イメージ パスもデータベースに保存されます。
私が必要とするのは、ユーザーがテーブルから行を削除したときに、画像も削除したいということです。
テーブルから行を削除する私のPHPは次のとおりです。
include('includes/temp.config.php');
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
// get the 'id' variable from the URL
$id = $_GET['id'];
// delete record from database
if ($stmt = $link->prepare("DELETE FROM templates WHERE id = ? LIMIT 1"))
{
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$link->close();
// redirect user after delete is successful
header("Location: edit.php");
}
else
// if the 'id' variable isn't set, redirect the user
{
header("Location: edit.php");
}
しかし、関連する画像の削除をどこから始めればよいかさえわかりません...どんな助けも大歓迎です。