php強製檔案下載(避免檔案或圖片直接在瀏覽器中開啟)
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
發布: 2016-07-25 09:00:51
-
-
- /**
- * FLEA_Helper_SendFile 类用于向浏览器发送文件
- *
- * 利用 FLEA_Helper_SendFile,应用程序可以将重要的文件保存在
- * 浏览器无法访问的位置。然后通过程序将文件内容发送给浏览器。
- * @site http://bbs.it-home.org
- */
- class FLEA_Helper_SendFile
- {
- /**
- * 向浏览器发送文件内容
- *
- * @param string $serverPath 文件在服务器上的路径(绝对或者相对路径)
- * @param string $filename 发送给浏览器的文件名(尽可能不要使用中文)
- * @param string $mimeType 指示文件类型
- */
- function sendFile($serverPath, $filename, $mimeType = 'application/octet-stream')
- {
- header("Content-Type: {$mimeType}");
- $filename = '"' . htmlspecialchars($filename) . '"';
- $filesize = filesize($serverPath);
- $charset = FLEA::getAppInf('responseCharset');//根据实际文件编码类型,如utf-8,gbk
- header("Content-Disposition: attachment; filename={$filename}; charset={$charset}");
- header('Pragma: cache');
- header('Cache-Control: public, must-revalidate, max-age=0');
- header("Content-Length: {$filesize}");
- readfile($serverPath);
- exit;
- }
- }
复制代码
|
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11