Home >Backend Development >PHP Problem >How to solve the php doc garbled problem
The solution to the garbled php doc: first open the corresponding code file; then add the statement "ob_end_clean()" before the Header.
Recommended: "PHP Video Tutorial"
PHP Download DOC Garbled Code
Recently done A system needs to download the doc file
After the previous code download is completed, it is always garbled when opened...
Google has not found a solution for a long time
Finally got it later
Must be cleared before Header, that is, ob_end_clean()
$file_size = filesize($logName); ob_end_clean(); header("Content-type:application/octet-stream"); header("Accept-Ranges:bytes"); header("Accept-Length:$file_size"); header("Content-Disposition:attachment;filename=" . $fileName); $fp = fopen($logName, "r"); $buffer_size = 1024; $cur_pos = 0; while (!feof($fp) && $file_size - $cur_pos > $buffer_size) { $buffer = fread($fp, $buffer_size); echo$buffer; $cur_pos+=$buffer_size; } $buffer = fread($fp, $file_size - $cur_pos); echo$buffer; fclose($fp); return true;
The above is the detailed content of How to solve the php doc garbled problem. For more information, please follow other related articles on the PHP Chinese website!