Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Headers used to download file php [duplicate]

Possible Duplicate:
php, file download

I have files that are not in the web root that I need to make available for download. So I have a script that uses the below to download the file requested. The problem is, I everyfile downloaded is corrupt? The files are ok because if I use FTP to download, they open. Here are the headers passed:

header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
        header("Cache-Control: public"); // needed for i.e.
        header("Content-Type: " . $download[0]['mime']);
        header("Content-Disposition: attachment; filename=" .$download_file);
        header("Content-Transfer-Encoding: Binary");
        header("Content-Length:".filesize($attachment_location));

        readfile($attachment_location);
like image 622
jhodgson4 Avatar asked Feb 02 '26 08:02

jhodgson4


1 Answers

Here is an example of headers used for that:
http://php.net/manual/en/function.readfile.php

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
like image 183
Almir Sarajčić Avatar answered Feb 03 '26 20:02

Almir Sarajčić



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!