TplController.class.php
1.55 KB
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
<?php
/**
* User: zoulongbo
* Date: 2018/7/26
* Time: 11:18
*/
namespace Apicp\Controller\Export;
use Com\PythonExcel;
use Common\Common\Constant;
use Common\Common\ExportDownload;
use Common\Common\User;
use Common\Common\UserCache;
use Common\Common\Vhall;
class TplController extends AbstractController
{
public function Index()
{
// 下载pdf文件
$data_path = APP_PATH . 'Data' . D_S . 'tpl.docx';
// 文件下载
if (!file_exists($data_path)) {
exit("下载失败");
}
$filename = '直播使用教程.docx';
$fileNameEncode = urlencode($filename);
$fileNameEncode = str_replace('+', '%20', $fileNameEncode);
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
if (stripos($userAgent, 'Firefox') !== false) {
$dispositionFileName = 'filename*="utf8\'\'' . $filename . '"';
} else {
$dispositionFileName = 'filename="' . $fileNameEncode . '"';
}
unset($filename, $fileNameEncode);
$file = fopen($data_path, "r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($data_path));
Header("Content-Disposition: attachment; {$dispositionFileName}");
echo fread($file, filesize($data_path));
$buffer = 1024;
while (!feof($file)) {
$file_data = fread($file, $buffer);
echo $file_data;
}
fclose($file);
exit;
}
}