-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_file.php
More file actions
36 lines (30 loc) · 977 Bytes
/
Copy pathdelete_file.php
File metadata and controls
36 lines (30 loc) · 977 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
<?php
/**
* Created by PhpStorm.
* User: Pauline
* Date: 12/04/2019
* Purpose: deletes file on module page from database
*/
session_start();
include("config.php");
if (!IsSet($_SESSION["userID"])) //user variable must exist in session to stay here
header("Location: login.php"); //if not, go back to login page
$username=$_SESSION["userID"]; //get user name into variable $username
//Processing input from module document table.php
$id=$_POST['id'];
$sql_query="SELECT filename FROM documents WHERE id='$id'";
$result = $db->query($sql_query);
while($row = $result->fetch_array()) {
$filename = $row['filename'];
//Delete data from database
$sql = "DELETE FROM documents WHERE id='$id'";
//check post to DB successful and redirect back to module page
if (mysqli_query($db, $sql)) {
unlink('uploads/'.$filename);
} else {
echo "Error: " . $sql . "<br" . mysqli_error($db);
}
}
header("location:module.php");
$db->close();
?>