I have an administration panel that has a page allowing the administrators to delete rows from the database. Each row they can delete has an associated image stored in a directory on the server. The image path is stored in the database as well.
What I need is when a user deletes a row from the table, I would like it to delete the image as well.
Here is my PHP to delete the row from the table:
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");
}
But I don’t even know where to start to delete the associated image… Any help would be greatly appreciated.
How about the
unlinkfunction?