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);
文件能够下载,但是图片打不开。以前能够打开。别的机器访问这个文件也能打开
------解决方案--------------------
首先检查是否有 BOM 头
不过 别的机器访问这个文件也能打开 ,那么可能性不大