有些类型文件(如txt,dat等),浏览器打开是默认是直接打开内容,也许你使用了<a href="url"></a>,但是浏览器才不管你那一套,照样直接打开。
我想实现直接下载怎么办:一下是php下载文件函数:
function downloadFile($file){
/*Coded by Alessio Delmonti*/
$file_name = $file;
$mime = 'application/force-download';
header('Pragma: public'); // required
header('Expires: 0'); // no cache
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private',false);
header('Content-Type: '.$mime);
header('Content-Disposition: attachment; filename="'.basename($file_name).'"');
header('Content-Transfer-Encoding: binary');
header('Connection: close');
readfile($file_name); // push it out
exit();
}