Php cannot open & nbsp; function & nbsp; fileDown ($ file_name) {& nbsp; & nbsp; $ file_name & nbsp; = & nbsp php file download image 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 "the 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 );
Files can be downloaded, but images cannot be opened. Previously opened. Other machines can access this file.
------ Solution --------------------
First, check whether the BOM header exists.
However, it is unlikely that other machines can access this file.