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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<?php include '../config.php'; // Check if the user is logged in
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) { header("Location: ../login.php"); }
ini_set('display_errors',0); ini_set('display_startup_errors',0); error_reporting(0);
//delete file if($_POST["clean_temp"] == 1){
$sql = "select * from temp_file where createdate <= ?"; $parameters = array(date("Y-m-d H:i:s", strtotime("-1 week"))); if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } while ($file_info = $sth->fetch(PDO::FETCH_ASSOC)) { unlink("uploads/" . $file_info{"file_name"});
$sql2 = "delete from temp_file where file_id = ?"; $parameters2 = array($file_info{"file_id"}); if (!($sth2 = $dbh->prepare($sql2))) { throw new Exception('[' . $sth2->errorCode() . ']: ' . print_r($sth2->errorInfo()));
}
if (!$sth2->execute($parameters2)) { throw new Exception('[' . $sth2->errorCode() . ']: ' . print_r($sth2->errorInfo())); } }
echo ("success");
}else{ $file_id = $_POST["file_id"]; $sql = "select * from temp_file where file_id = ?"; $parameters = array($file_id); if (!($sth = $dbh->prepare($sql))) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); }
if (!$sth->execute($parameters)) { throw new Exception('[' . $sth->errorCode() . ']: ' . print_r($sth->errorInfo())); } $file_info = $sth->fetch(PDO::FETCH_ASSOC);
if (!unlink("uploads/".$file_info{"file_name"})){ echo ("fail"); } else { echo ("success"); } }
?>
|