1.text.txt
huahua
huahua
huahua
2.download.html
<a href="download.php?filename=./text.txt">文件下载</a>
3.download.php
<?php //获取要下载的文件名 $filename = $_GET['filename']; //设置头信息 header('Content-Disposition:attachment;filename=' . basename($filename)); header('Content-Length:' . filesize($filename)); //清理缓存 ob_clean(); //读取文件并写入到输出缓冲 readfile($filename);