-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_resource.php
More file actions
40 lines (33 loc) · 843 Bytes
/
delete_resource.php
File metadata and controls
40 lines (33 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
session_start();
if (!isset($_SESSION['staff'])) {
header("Location: staff_login.php");
exit();
}
if (!isset($_GET['id'])) {
header("Location: staff_resources.php");
exit();
}
include 'connection.php';
$id = intval($_GET['id']);
// Get the resource to delete file from server
$sql = "SELECT file_path FROM resources WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->bind_result($file_path);
$stmt->fetch();
$stmt->close();
// Delete the file from server if exists
if ($file_path && file_exists($file_path)) {
unlink($file_path);
}
// Delete the resource record from database
$sql = "DELETE FROM resources WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();
$stmt->close();
header("Location: staff_resources.php");
exit();
?>