<body>
    <?php
        $zip = new ZipArchive;
        if ($zip->open(getcwd() .'/read.zip', ZipArchive::CREATE) === TRUE) {
            $zip->addFile(getcwd() . '/read.txt','/newname.txt');
            $zip->close();
            $file = getcwd() . '/read.zip';
             // http headers for zip downloads
            header("Pragma: public");
            header("Expires: 0");
            header("Cache-Control: public");
            header("Content-Description: File Transfer");
            header("Content-type: application/octet-stream");
            header("Content-Disposition: attachment; filename=\"read.zip\"");
            header("Content-Transfer-Encoding: binary");
            header("Content-Length: ".filesize($file));
            readfile($file);
            echo 'ok';
        } else {
            echo 'failed';
        }
    ?>
</body>
I have following code and want to download zip file automatically that is being produced by this code when we run this page.