首页 > 网站 > 建站经验 > 正文

php文件下载函数

2024-04-25 20:35:57
字体:
来源:转载
供稿:网友

/**

* 文件下载

* @param $filepath 文件路径

* @param $filename 文件名称

*/

function file_down($filepath, $filename = '') {

if(!$filename) $filename = basename($filepath);

if(is_ie()) $filename = rawurlencode($filename);

$filetype = fileext($filename);

$filesize = sprintf("%u", filesize($filepath));

if(ob_get_length() !== false) @ob_end_clean();

header('Pragma: public');

header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');

header('Cache-Control: no-store, no-cache, must-revalidate');

header('Cache-Control: pre-check=0, post-check=0, max-age=0');

header('Content-Transfer-Encoding: binary');

header('Content-Encoding: none');

header('Content-type: '.$filetype);

header('Content-Disposition: attachment; filename="'.$filename.'"');

header('Content-length: '.$filesize);

readfile($filepath);

exit;

}

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表