-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeletepost.php
54 lines (47 loc) · 1.23 KB
/
deletepost.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
include "./library/autoload.php";
include "./library/security.php";
if ($_SERVER["REQUEST_METHOD"] == "GET")
{
try
{
$db = new DatabaseConnection();
$connection = $db->get_connection();
$query = "SELECT post FROM post WHERE pid = :pid";
$statement = $connection->prepare($query);
$statement->bindParam(":pid", $_GET['pid']);
$statement->execute();
$statement->setFetchMode(PDO::FETCH_ASSOC);
$result = $statement->fetch();
$dir = $result['post'];
delete_directory($dir);
$query = "DELETE FROM post WHERE pid = :pid";
$statement = $connection->prepare($query);
$statement->bindParam(":pid", $_GET['pid']);
$statement->execute();
}
catch (PDOException $ex)
{
Logger::write_log("deletepost.php", $ex->getMessage());
}
}
function delete_directory($path)
{
if (substr($path, strlen($path) - 1, 1) != '/')
{
$path .= '/';
}
$files = glob($path . '*', GLOB_MARK);
foreach ($files as $file)
{
if (is_dir($file))
{
delete_directory($file);
}
else
{
unlink($file);
}
}
rmdir($path);
}