php文件下载封装成一个类 老是多出3个字节,请问哪里错了?
class filedown {
public $filename;
public $filesize;
//转码 gb2312
function __construct($filename){
$this->filename=iconv(utf-8,gb2312,$filename);
}
function down (){
//$_server['document_root']当前运行脚本所在的文档根目录。在服务器配置文件中定义。
$path=$_server['document_root']./12/.$this->filename;
if(!file_exists($path)){
die(文件不存在);
}
$fp=fopen($path,r); //读入
$this->filesize=filesize($path);
//返回文件的头 浏览器靠头识别下载 //返回
//返回的文件类型 流 可以是文本 二进制
header(content-type: application/octet-stream);
//按照字节大小返回
header(accept-ranges: bytes);
//返回文件大小
header(accept-length: $this->filesize);
//这里客户端的弹出对话框,对应的文件名
header(content-disposition: attachment; filename=.$this->filename);
$count=0;
$buffer=1024;
while(!feof($fp)&& $this->filesize-$count>0){
$filedata=fread($fp,$buffer);
$count+=$buffer;
echo $filedata;
}
fclose($fp);
}
}
$fd=new filedown(白羊座.png);
$fd->down ();
分享到: 更多
------解决办法--------------------
http://baike.baidu.com/subview/126558/5073178.htm