-
Notifications
You must be signed in to change notification settings - Fork 0
/
destroyer.php
65 lines (55 loc) · 1.35 KB
/
destroyer.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
<?php
//Initializing Variables
$rawSize = $_POST["filesize"];
$unit = $_POST["unit"];
$trueSize;
$name = $_POST['filename'];
$ext = $_POST['ext'];
$filename = $name . $ext;
$path = $_SERVER['DOCUMENT_ROOT'];
$filepath = $path . "/" . $filename;
//True size
switch ($unit) {
case "b":
$trueSize = $rawSize;
break;
case "kb":
$trueSize = $rawSize * 1024;
break;
case "mb":
$trueSize = $rawSize * pow(1024, 2);
break;
case "gb":
$trueSize = $rawSize * pow(1024, 3);
break;
}
//echo "$filepath Raw: $rawSize True: $trueSize";
createfile($filename, $trueSize);
downloadfile($filename, $filepath);
////////////
//Funtions//
////////////
//Create file function
function createfile($filename, $trueSize)
{
$fh = fopen($filename, 'w');
//$size = 1024 * 1024 * 10; // 10mb
$chunk = 1024;
while ($trueSize > 0) {
fputs($fh, str_pad('', min($chunk, $trueSize)));
$trueSize -= $chunk;
}
fclose($fh);
};
//Download file function
function downloadfile($filename, $filepath)
{
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header("Content-Length: " . filesize($filepath));
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
readfile($filepath);
unlink($filename);
};