Search code examples
phpzipforce-download

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.


Solution

  • <?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;
    ?>