浙江雁荡山 发表于 2017-3-23 11:53:45

php 实现文本下载

$file_name="a.txt";
//Windows PATH;
$file_path=dirname(__FILE__).'\\' . $file_name;
//下载文件需要用到的头
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment; filename=".$file_name);
Header("Accept-Length: ".filesize($file_path));
//首先要判断给定的文件存在与否
if(!file_exists($file_path)){
echo "没有该文件文件";
return ;
}
readfile($file_path);

  设置好header后,(header的含义网上有)
  需要做的一件事,是关闭迅雷的下载监听(或者其他类似的下载浏览器)
  

 
  然后重新测试你的代码
  参考:http://99webtools.com/php-force-file-download.php
页: [1]
查看完整版本: php 实现文本下载