What to do if php downloads doc garbled characters

藏色散人
Release: 2023-03-09 22:22:02
Original
1580 people have browsed it

The solution to garbled php downloaded doc: first open the corresponding code file; then clean it through "ob_end_clean()" before the Header.

What to do if php downloads doc garbled characters

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

PHP download DOC garbled code?

I recently built a system that required downloading the doc file

After the previous code was downloaded, it was always garbled when opened...

I haven’t found it on Google for a long time. Solution

Finally got it done later

Must be cleaned 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;
Copy after login

Recommended learning: "PHP Video Tutorial

The above is the detailed content of What to do if php downloads doc garbled characters. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!