-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivityLogger.php
50 lines (41 loc) · 1.01 KB
/
activityLogger.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
<?php
function getDirectory() {
return dirname(__FILE__);
}
function getAbsolutePath($filename) {
return getDirectory().'/'.$filename;
}
function logDownload($filename) {
if (!is_writable(getDirectory())) {
return;
}
$logPath = getAbsolutePath('activity.log');
$entry = "\n".date('l d/m/y g:i A').' - '.$filename;
$fh = fopen($logPath, 'a');
fwrite($fh, $entry);
fclose($fh);
}
if (!isset($_GET['file'])) {
exit();
} else {
$path = $_GET['file'];
unset($_GET['file']);
if (!empty($_GET['file'])) {
$path .= '&'.implode('&', array_keys($_GET));
}
$file = getAbsolutePath($path.'.mp3');
if (!file_exists($file)) {
header("HTTP/1.0 404 Not Found");
exit();
}
}
$filename = basename($file);
logDownload($filename);
header('Content-Description: File Transfer');
header('Content-Type: audio/mpeg');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Length: '.filesize($file));
header('Expires: 0');
header('Pragma: public');
header('Cache-Control: public');
readfile($file);