PHP中怎么用代码实现文件下载

我在做一个网站PHP的,,需要从固定网站上找自己想要的东西,,想用代码实现,,麻烦问一下怎么写这个代码1!!!!!急急急急急!!!

第1个回答  2012-03-21
CI框架:
前台:a.php <a href="download/export">download</a>
后台:download.php

function export(){
//把js,css的路径文件名填充下面的$url和$fname就可以了
//至于html文件,先在后台生成一个html文件,然后下载就可以了
$fname=date('YmdHis').'.xls';
$url='./xls/'.$fname;
$this->excel_m->write($url);

$file = fopen($url,"r"); // 打开文件
// 输入文件标签
header('Content-Encoding: utf-8');
header("Content-type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($url));
header('Content-Transfer-Encoding: binary' );
header("Content-Disposition: attachment; filename=" .$fname); //以真实文件名提供给浏览器下载
header('Pragma: no-cache');
header('Expires: 0');
//输出文件内容
echo fread($file,filesize($url));
fclose($file);
}
第2个回答  2010-07-15
直接写一个链接,链接到你要下载的文件的路径,比如文件在您网站的根目录的\download下
<a href="./download/文件.rar"></a>本回答被提问者采纳
第3个回答  2010-07-21
啊。。。究竟在问什么呢?固定网站?搜索功能?糊里糊涂的。。。直接加个超链接不行吗?