求一个稳定的点击下载代码 是用来备份数据库的,生成一个txt文件,直接弹出对话框给用户下载。用了很多了,大致都是在HEADER里面定义然后输出缓冲,但经过客户使用,发现很不稳定,有的时候会提示下载,有的时候就是直接输入内容,请问大家都是怎么做的??我使用过网易邮箱的附件下载,发现非常稳定,从来都没有出现过直接打开附件的问题。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $fname=$_GET["fname"];function do_download($downloadfile){ $file = fopen($downloadfile,"r"); if (!$file) { echo "文件找不到"; } else { if(ereg("http://",$downloadfile) || ereg("ftp://",$downloadfile)) { Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Content-Disposition: attachment; filename=".basename($downloadfile)); while (!feof($file)) { //echo fread($file,1024); echo fgets($file,1024); } fclose ($file); } else { Header("Content-type: application/octet-stream"); Header("Accept-Ranges: bytes"); Header("Content-Disposition: attachment; filename=".basename($downloadfile)); echo fread($file,filesize($downloadfile)); fclose($file); } }fclose ($file);}do_download($fname); <a href="http://www.ccidcom.com/blog/u/632/index.html">我的博客</a> 100分求PHP开发环境 小鸟请教啊!!! PHP 怎么获取客户机的每一个请求 求教php大神 数组元素出现次数的问题,在线等 mysql连接问题?急救! 请问不能调用php的函数,是怎么回事? 怎样用php发送html的邮件? Windows 98下安装Apache(PWS) PHP4 MySQL phpMyAdmin的方法 在线等分。。。。。 ecshop,wstmart和iwebshop,开源商城系统怎么选择 如何实现windows弹出框方式的密码验证 关于正则表达式 脚本之间变量传递问题
function do_download($downloadfile){
$file = fopen($downloadfile,"r");
if (!$file)
{
echo "文件找不到";
}
else
{
if(ereg("http://",$downloadfile) || ereg("ftp://",$downloadfile))
{
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-Disposition: attachment; filename=".basename($downloadfile));
while (!feof($file))
{
//echo fread($file,1024);
echo fgets($file,1024);
}
fclose ($file);
}
else
{
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-Disposition: attachment; filename=".basename($downloadfile));
echo fread($file,filesize($downloadfile));
fclose($file);
}
}
fclose ($file);
}do_download($fname);