-
-
- /**
- * The FLEA_Helper_SendFile class is used to send files to the browser
- *
- * Using FLEA_Helper_SendFile, applications can save important files in
- * locations that are inaccessible to the browser. The file contents are then sent to the browser through the program.
- * @site http://bbs.it-home.org
- */
- class FLEA_Helper_SendFile
- {
- /**
- * Send the file content to the browser
- *
- * @param string $serverPath The path of the file on the server (absolute or relative path)
- * @param string $filename The file name sent to the browser (do not use Chinese if possible)
- * @param string $mimeType indicates the file type
- */
- function sendFile($serverPath, $filename, $mimeType = 'application/octet- stream')
- {
- header("Content-Type: {$mimeType}");
- $filename = '"' . htmlspecialchars($filename) . '"';
- $filesize = filesize($serverPath);
- $ charset = FLEA::getAppInf('responseCharset');//According to the actual file encoding type, such as 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;
- }
- }
Copy code
|