简体   繁体   English

readfile下载损坏的文件

[英]readfile downloads corrupt files

I am facing a problem when i am trying to download a certain file from my localhost. 当我尝试从本地主机下载某个文件时遇到问题。 Everytime i download a file, either a .docx, a .pdf or a .png it is always corrupt. 每次下载文件时,无论是.docx,.pdf还是.png,它总是损坏的。 I have spend multiple hours on finding a solution but nothing seems to work. 我花了多个小时来寻找解决方案,但似乎没有任何效果。

This is the script im running : 这是我正在运行的脚本:

$file_download="loonadministratie/{$loon_id}/{$file}";
        if (file_exists($file_download)) {
                header('Content-Description: File Transfer');
                header("Content-Type: application/octet-stream/loonadministratie/{$loon_id}/");
                header('Content-Disposition: attachment; filename='.basename($file_download));
                header('Expires: 0');
                header('Cache-Control: must-revalidate');
                header('Pragma: public');
                header('Content-Length: ' . filesize($file_download));
                readfile($file_download);
                exit;
            }

Thanks in forehand 正手感谢

Try 尝试

<?php
if (ob_get_level()) ob_end_clean();
?>

It may be the issue 可能是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM