-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.php
104 lines (82 loc) · 2.59 KB
/
file.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
//Download file link
if(isset($_GET['sig']) && isset($_GET['h']) && isset($_GET['t']) && isset($_GET['download']))
{
include_once('config.php');
$ip = $_SERVER['REMOTE_ADDR'];
$signature = $_GET['sig'];
$hashGiven = $_GET['h'];
$timestamp = $_GET['t'];
$hash = md5($salt . $timestamp . $signature);
if($hashGiven == $hash && $timestamp >= time())
{
$filehash = $signature;
$sql = "SELECT * FROM {$tbl_prefex}files WHERE filehash=:filehash LIMIT 1";
$query = $handler->prepare($sql);
$query->execute(array(':filehash'=>$filehash));
if ($row=$query->fetch())
{
$filehash = $row["filehash"];
$filename = $row["filename"];
$filesize = $row["filesize"];
$mime = $row["mime"];
if(file_exists("$upload/$filehash"))
{
$filePath = "$upload/$filehash";
header("Content-Description: File Transfer");
header("Content-Type: $mime");
header("Content-Length: ".$filesize);
header("Content-disposition: attachment; filename=\"" . basename($filename) . "\"");
readfile($filePath);
}
}
}
}
//Delete file link
else if(isset($_GET['sig']) && isset($_GET['h']) && isset($_GET['t']) && isset($_GET['delete']))
{
include_once('config.php');
$ip = $_SERVER['REMOTE_ADDR'];
$signature = $_GET['sig'];
$hashGiven = $_GET['h'];
$timestamp = $_GET['t'];
$hash = md5($salt . $timestamp . $signature);
if($hashGiven == $hash && $timestamp >= time())
{
$filehash = $signature;
$sql = "SELECT * FROM {$tbl_prefex}files WHERE filehash=:filehash LIMIT 1";
$query = $handler->prepare($sql);
$query->execute(array(':filehash'=>$filehash));
if ($row=$query->fetch())
{
$id = $row["id"];
$filehash = $row["filehash"];
$filename = $row["filename"];
$filesize = $row["filesize"];
$mime = $row["mime"];
if(file_exists("$upload/$filehash"))
{
$filePath = "$upload/$filehash";
unlink($filePath);
$sql = "DELETE FROM {$tbl_prefex}files WHERE id=:id LIMIT 1";
$delete_file = $handler->prepare($sql);
$delete_file->execute(array(':id'=>$id));
$sql = "DELETE FROM {$tbl_prefex}scans WHERE file_id=:id";
$delete_file_scans = $handler->prepare($sql);
$delete_file_scans->execute(array(':id'=>$id));
header('Content-Type: application/json');
$data = array('success'=>'File deleted.');
echo json_encode($data);
die();
}
}
}
$data = array('error'=>'File not deleted.');
echo json_encode($data);
die();
}
else
{
exit("file doesn't exist (c)");
}
?>