-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-delete.php
30 lines (24 loc) · 1020 Bytes
/
file-delete.php
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
<?php
session_start();
if(session_status() !== PHP_SESSION_ACTIVE) {
throw new Exception('Erreur lors de l\'initialisation de la session');
}
if (!isset($_SESSION['user'])) {header('Location: login.php');}
require_once('./database/connection.php');
$connection = connectionDb();
if(isset($_POST['fileId'])) {
// echo '<pre>';
// var_dump($_POST);
// echo '</pre>';
$query = $connection->prepare('SELECT * FROM files WHERE id = :fileId AND userId = :userId');
$query->execute(['fileId' => $_POST['fileId'], 'userId' => $_SESSION['user']['id']]);
$result = $query->fetch(PDO::FETCH_ASSOC);
if(!empty($result)) {
$fileName = $result['filename'];
unlink($fileName);
$query = $connection->prepare('DELETE FROM files WHERE id = :fileId AND userId = :userId');
$query->execute(['fileId' => $_POST['fileId'], 'userId' => $_SESSION['user']['id']]);
}
}
header('Location: user.php');
?>