正在显示
1 个修改的文件
包含
14 行增加
和
4 行删除
@@ -26,18 +26,28 @@ class Attachment extends Base { | @@ -26,18 +26,28 @@ class Attachment extends Base { | ||
26 | $filename = PUBLIC_PATH.$path; | 26 | $filename = PUBLIC_PATH.$path; |
27 | if(file_exists($filename)){ | 27 | if(file_exists($filename)){ |
28 | $file = new \SplFileInfo($filename); | 28 | $file = new \SplFileInfo($filename); |
29 | - if(in_array($file->getExtension(),['jpg','jpeg','png','gif','mp4','mp3','pdf','txt','doc','docx','xls','xlsx','ppt','pptx','eml'])){ | ||
30 | - app()->header("Content-Type",$file->getType()); | 29 | + // 'doc','docx','xls','xlsx','ppt','pptx' |
30 | + if(in_array($file->getExtension(),[ | ||
31 | + 'jpg','jpeg','png','gif','mp4','mp3','pdf','txt','eml','log','html','htm','htmls','xml','md' | ||
32 | + ])){ | ||
33 | + $mime = mime_content_type($file->getRealPath()); | ||
34 | + // 邮件类型 | ||
35 | + if (str_contains($mime, 'message/')){ | ||
36 | + $mime = "text/plain"; | ||
37 | + }else { | ||
31 | app()->header("Content-Disposition","inline; filename=".$file->getFilename()); | 38 | app()->header("Content-Disposition","inline; filename=".$file->getFilename()); |
32 | app()->header("Content-Transfer-Encoding","binary"); | 39 | app()->header("Content-Transfer-Encoding","binary"); |
33 | app()->header("Accept-Ranges","bytes"); | 40 | app()->header("Accept-Ranges","bytes"); |
41 | + } | ||
42 | + app()->header("Content-Type",$mime); | ||
43 | + | ||
34 | app()->header("Content-Length",$file->getSize()); | 44 | app()->header("Content-Length",$file->getSize()); |
35 | - app()->header("Cache-Control","max-age=0"); | 45 | + app()->header("Cache-Control","public, max-age=31536000"); |
36 | app()->header("Last-Modified",$file->getMTime()); | 46 | app()->header("Last-Modified",$file->getMTime()); |
37 | app()->header("Expires",gmdate("D, d M Y H:i:s", time() + 3600 * 24 * 365) . " GMT"); | 47 | app()->header("Expires",gmdate("D, d M Y H:i:s", time() + 3600 * 24 * 365) . " GMT"); |
38 | return file_get_contents($file->getPathname()) ; | 48 | return file_get_contents($file->getPathname()) ; |
39 | } | 49 | } |
40 | - return "<div style='text-align: center'>“".$file->getFilename()."“ 当前附件不支持预览</div>"; | 50 | + return "<div style='text-align: center'>当前附件不支持预览</div>"; |
41 | } | 51 | } |
42 | return "<div style='text-align: center'>404 附件不存在</div>"; | 52 | return "<div style='text-align: center'>404 附件不存在</div>"; |
43 | } | 53 | } |
-
请 注册 或 登录 后发表评论