send zip file to browser / force direct download

Martin Huwa picture Martin Huwa · Sep 19, 2011 · Viewed 51.2k times · Source

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.

Answer

Amber picture Amber · Sep 19, 2011
<?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;
?>