blob: 1b7731c070d96920e0ebfc5ff108a9ac67b931db (
plain) (
blame)
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
|
<?php
session_start();
if ( !$_SESSION["logged"] )
{
header("Location: /index.php");
exit();
}
function send($id)
{
$path = "../../private/downloads.txt";
if ( !($fd = fopen($path, "r")) )
{
$_SESSION["communicates"]["serverError"] = "<span style='color:red'>Server error! Mail admin at admin@{$_SERVER['HTTP_HOST']}</span>";
header("Location: ../fileManager.php");
return;
}
$found = false;
while (!feof($fd))
{
$line = trim(fgets($fd));
$arr = explode(";", $line);
if ( count($arr) == 4 )
{
if ( $id === $arr[0] )
{
$found = true;
$path = $arr[2];
$name = $arr[1];
break;
}
}
}
//var_dump($found);
//var_dump($path . $id);
//var_dump(!file_exists($path . $id));
if ( !$found || !file_exists($path . $id) )
{
$_SESSION["communicates"]["fileError"] = "<span style='color:red'>No file with given id!</span>";
return;
}
$fd = fopen($path . $id, "r");
$size = filesize($path . $id);
//$contents = fread($fd, $size);
fclose($fd);
header("Content-Type: application/octet-stream");
header("Content-Length: $size;");
header('Content-Disposition: attachment; filename="'.$name.'"');
echo file_get_contents($path . $id);
//echo $contents;
}
if ( !empty($_GET['fileid']) )
send($_GET['fileid']);
else
{
$_SESSION["communicates"]["fileError"] = "<span style='color:red'>No file id given!</span>";
header("Location: ../fileManager.php");
}
?>
|