0

if i open the zip-file, winrar says:"Unexpected end of archive" without ob_start the zip creation works but not the download. die(); does not work

<?php 
            $images = glob("bilder/*.*");
            ob_start();
            for ($i=0; $i <count($images) ; $i++) {


                echo '<ul id="table"><li><a class="fancybox" rel="gallery1" href="'. $images[$i]. '"><img src="'. $images[$i].'" height="90" width="160" alt=""/></a>
                        <div><label><input id="check" type="checkbox" name="img[]" value="'.$images[$i].'"/></label></div></li></ul>';
            }

            if (isset($_POST["img"])){
            $images = $_POST["img"];
            $zip = new ZipArchive();
            $ip = gethostbyaddr($_SERVER["REMOTE_ADDR"]);
            $filename = "./".$ip.".zip";
            if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
                exit("cannot open <$filename>\n");
            }
            for ($i=0; $i < count($images); $i++) { 
                $zip->addFile($images[$i]);
            }
            $zip->close();

            header('Content-Type: application/zip');
            header('Content-disposition: attachment; filename='.$filename);
            header('Content-Length: ' . filesize($filename));
            readfile($filename);
            die();
            }
            ob_end_flush();
            ?>
            <input type="submit" value="Download">
            </form>
FLOTZOR
  • 9
  • 4

1 Answers1

0

Add die() after your readfile and try again. Without die, you still print html, this will corrupt your output.

Kevin Labécot
  • 2,005
  • 13
  • 25