PHP download file picture cannot be opened
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 "file does not exist";
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);
The file can be downloaded, but the picture won't open. Previously able to open. Other machine access to this file can also be opened
------Solution--------------------
First check if there is a BOM header
But other machines can access this file, so it's unlikely.