Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send zip file to browser / force direct download

i created with php zip ( http://php.net/manual/de/book.zip.php ) a zip file

now i have to send it to the browser / force a download for it.

like image 981
Martin Huwa Avatar asked Sep 19 '11 12:09

Martin Huwa


People also ask

How do I download zip files to my browser?

Google Chrome saves zip files as zip file by default. If not, you can right-click the zip-file link (if you have a right mouse button). It will say, "save link as".


1 Answers

<?php
    // or however you get the path
    $yourfile = "/path/to/some_file.zip";

    $file_name = basename($yourfile);

    header("Content-Type: application/zip");
    header("Content-Disposition: attachment; filename=$file_name");
    header("Content-Length: " . filesize($yourfile));

    readfile($yourfile);
    exit;
?>
like image 94
Amber Avatar answered Sep 18 '22 11:09

Amber