日期:2014-05-17 浏览次数:20496 次
function fileDown($file_name){
$file_name = iconv("utf-8","gb2312",$file_name);
$file_path = "E:/php/down/".$file_name;
if(!file_exists($file_path)){
echo "文件不存在";
return;
}
$fp = fopen($file_path,"r");
$file_size = filesize($file_path);
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Accept-Length: $file_size");
Header("Content-Disposition: attachment; filename=".$file_name);
$buffer = 1024;
$file_count = 0;
while(!feof($fp) && ($file_size - $file_count>0)){
$file_data = fread($fp,$buffer);
$file_count += $buffer;
echo $file_data;
}
fclose($fp);
}
$file_name="sai.png";
fileDown($file_name);