方法一
a标签H5属性download属性,<a download='test.txt' href='http://www.baidu.com'>下载test.txt文件</a>
方法二
PHP直接输出
ob_start();
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$size=readfile($filename);
//var_dump($size);exit;
Header( "Content-type:application/octet-stream");
Header( "Accept-Ranges:bytes");
Header( "Accept-Length:");
header( "Content-Disposition: attachment; filename= $title");
//echo file_get_contents($size);
exit;
方法三
$filename=$_GPC['url'];
$title=substr($filename,strrpos($filename,'/')+1);
$file = fopen($filename, "rb");
Header( "Content-type: application/octet-stream ");
Header( "Accept-Ranges: bytes ");
Header( "Content-Disposition: attachment; filename= $title");
$contents = "";
while (!feof($file)) {
$contents .= fread($file, 8192);
}
echo $contents;
fclose($file);