简体   繁体   中英

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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