Home >Backend Development >PHP Problem >How to solve the php doc garbled problem

How to solve the php doc garbled problem

藏色散人
藏色散人Original
2020-10-06 13:43:141930browse

The solution to the garbled php doc: first open the corresponding code file; then add the statement "ob_end_clean()" before the Header.

How to solve the php doc garbled problem

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!

Statement:
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