php下载TXT文件
程序员文章站
2024-03-01 17:36:10
...
//下载TXT文件
//注意:这里不能用异步请求
public function download(){
$file_path = $this->request->get('file_path');
$filename = ROOT_PATH.'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$file_path;
//检测是否设置文件名和文件是否存在
if ((isset($filename))&&(file_exists($filename))){
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filename));
readfile($filename);
} else {
echo "文件不存在!";
}
}
上一篇: mysql生成随机字符串函数分享