Attachment.php
1.5 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
56
57
58
59
60
<?php
namespace Controller;
use Lib\Err;
use Lib\Imap\ImapConfig;
use Lib\Imap\ImapPool;
use Lib\Mail\MailFun;
use Model\folderSql;
use Model\listsSql;
/**
* 附件预览
* @author:dc
* @time 2025/8/19 17:43
* Class Attachment
* @package Controller
*/
class Attachment extends Base {
public function show(){
$path = app()->request('path');
$filename = PUBLIC_PATH.$path;
if(file_exists($filename)){
$file = new \SplFileInfo($filename);
if(in_array($file->getExtension(),['jpg','jpeg','png','gif','mp4','mp3','pdf','txt','doc','docx','xls','xlsx','ppt','pptx','eml'])){
app()->header("Content-Type",$file->getType());
app()->header("Content-Disposition","inline; filename=".$file->getFilename());
app()->header("Content-Transfer-Encoding","binary");
app()->header("Accept-Ranges","bytes");
app()->header("Content-Length",$file->getSize());
app()->header("Cache-Control","max-age=0");
app()->header("Last-Modified",$file->getMTime());
app()->header("Expires",gmdate("D, d M Y H:i:s", time() + 3600 * 24 * 365) . " GMT");
return file_get_contents($file->getPathname()) ;
}
return "<div style='text-align: center'>“".$file->getFilename()."“ 当前附件不支持预览</div>";
}
return "<div style='text-align: center'>404 附件不存在</div>";
}
}