-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
DownloadForced.php
34 lines (27 loc) · 984 Bytes
/
DownloadForced.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
<?php
die('Not allowed');
function downloadFile($dlFile, $dlSize) {
// Must be fresh start
if (headers_sent())
die('Headers Sent');
// Required for some browsers
if (ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"" . basename($dlFile) . "\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $dlSize);
ob_clean();
flush();
readfile($dlFile);
}
if (! (empty($_GET["file"]) || empty($_GET["size"]))) {
$dlFile = htmlspecialchars($_GET["file"]);
$dlSize = htmlspecialchars($_GET["size"]);
downloadFile($dlFile, $dlSize);
}
?>