当前位置:Gxlcms > PHP教程 > php文件下载功能实现_PHP教程

php文件下载功能实现_PHP教程

时间:2021-07-01 10:21:17 帮助过:23人阅读

/**
* 文件下载功能
* @param string $fileName 文件名称
* @param string $fileExt 文件后缀名称
*/
function downloadFile($fileName, $fileExt = '.txt' )
{
if( empty($fileName)) return FALSE;
$fileName .= $fileExt;
$filePath = TEMI_UPLOAD_PATH . $fileName;
$file = fopen($filePath, "r");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: " . filesize($filePath));
Header("Content-Disposition: attachment; filename=" . $fileName);
echo fread($file, filesize($filePath));
fclose($file);
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477902.htmlTechArticle?php /** * 文件下载功能 * @param string $fileName 文件名称 * @param string $fileExt 文件后缀名称 */ function downloadFile($fileName, $fileExt = .txt ) { if( empty($f...

人气教程排行