Do not extract .zip files after downloading using PHP

I upload my file with file .zipusing this PHP class:

public function download($file)
    {
        $filename = $this->dir . $file;
        $fp = fopen($filename, "rb");
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-type: application/octet-stream");
        header("Content-length: " . filesize($filename));
        header("Content-disposition: attachment;filename = " . $file . "");
        header("Content-Transfer-Encoding: binary");
        readfile($filename);
        ob_end_clean();
        die(fpassthru($fp));
        fclose($fp);
    }

this worked and I uploaded the file .zipsuccessfully. but when I need to extract the file .zipusing winrar, I see this error:

db-backup-2014-11-15_14-18-48-12.zip: The archive is either in unknown format or damaged.

in download:

enter image description here

in the opened:

enter image description here

in excerpt:

enter image description here

NOTE. my source file worked and was perfectly extracted using winrar.

I think my problem is CRC32 = 0000000 (on the first screen), because there is a true value in the source file.

how to fix this problem ?!

+4
source share
2 answers

ZIP , PHP script ?>, ZIP-. , PHP ?> script, download() ( , , <?php), . , . ?> , , ( ).

+4

:

<?php    
    public function download($file)  {
        ob_end_clean();
        $filename = $this->dir . $file;
        header("Content-Type: application/zip");
        header("Content-Disposition: attachment; filename=". pathinfo($filename , PATHINFO_BASENAME));
        header("Content-Length: " . filesize($filename ));
        readfile($fileName);
    }
+1

All Articles