-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_message.php
More file actions
35 lines (29 loc) · 1.03 KB
/
delete_message.php
File metadata and controls
35 lines (29 loc) · 1.03 KB
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
<?php
include 'connect.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get user ID and message datetime from the request
$userId = $_POST['userId'];
$datetime = $_POST['datetime'];
// Query the database to get the media file path
$query = "SELECT media FROM chat WHERE iduser = ? AND datetime = ?";
$stmt = $pdo->prepare($query);
$stmt->execute([$userId, $datetime]);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if ($result) {
$mediaPath = $result['media'];
$deleteQuery = "DELETE FROM chat WHERE iduser = ? AND datetime = ?";
$deleteStmt = $pdo->prepare($deleteQuery);
$deleteStmt->execute([$userId, $datetime]);
if (file_exists($mediaPath)) {
unlink($mediaPath);
}
echo 'Message and media deleted successfully';
} else {
echo 'Message not found';
}
} else {
// Handle invalid requests or direct access to this script
header('HTTP/1.0 403 Forbidden');
echo 'Access Denied';
}
?>