其他分享
首页 > 其他分享> > 文件下载函数

文件下载函数

作者:互联网

function download($file_path,$file_name){

$file_name = iconv("UTF-8","GB2312",$file_name);

$file = $file_path.$file_name;


if(!file_exists($file)){

echo "该文件不存在";

die();

}

$filesize = filesize($file);

$fp = fopen($file,"r");

//返回的文件

header("Content-type: application/octet-stream");

//按照字节大小返回

header("Accept-Ranges: bytes");

//返回文件大小

header("Accept-Length: $filesize");

//这里客户端的弹出对话框,对应的文件名

header("Content-Disposition: attachment; filename=".$file_name);

$buffer = 1024;

$count = 0;

while(!feof($fp) || ($count< $filesize)){

$data = fread($fp,$buffer);

$count+=$buffer;

echo $data;

}

fclose($fp);

}

标签:fp,文件,函数,buffer,header,filesize,file,下载,name
来源: https://blog.51cto.com/u_12953715/2738932