Recently updated a project. The download part follows the download code of the previous project. But this time there was a small problem. The downloaded word and other files will prompt garbled characters, when downloading files such as rar, the system prompts that the file has been damaged and the cause has not been determined for a long time. After the problem is solved in an uncertain way, record the problem and wait for additional reasons.
$ Extend = explode ('.', $ file_info-> path );
$ Ext = array_pop ($ extend );
$ File_name = $ file_info-> file_name. '.'. $ ext;
$ File = fopen ($ file_info-> path, "r ");
Header ("Content-type: application/octet-stream ");
Header ("Accept-Ranges: bytes ");
Header ("Accept-Length:". filesize ($ file_info-> path ));
Header ("Content-Disposition: attachment; filename =". $ file_name );
Ob_clean (); # The newly added code
Flush (); # New code
Echo fread ($ file, filesize ($ file_info-> path ));
Fclose ($ file );
Note: If the downloaded file name is Chinese, it will be garbled and can be converted to utf8 or pinyin.