-
Notifications
You must be signed in to change notification settings - Fork 0
/
download.php
37 lines (29 loc) · 959 Bytes
/
download.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
<?php
$fileParam = $_GET['file'];
$fileName = urldecode($fileParam);
$type = 'application/pdf';
$download = new FileDownload($fileName, $type);
$download->send();
final class FileDownload {
private $fileName;
private $type;
function __construct($fileName, $type) {
$this->fileName = $fileName;
$this->type = $type;
}
public function send() {
// send header
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $this->fileName);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($this->fileName));
// send file
ob_clean();
flush();
readfile($this->fileName);
}
}