I download my back file with .zip
format using 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 downloaded .zip
file successful. but when i need to extract .zip
file using 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 :
in open:
in extract :
NOTE: my original file worked and fine extracted using winrar.
i think my problem is CRC32 = 0000000 (in screen one) because in original file is have a true value.
how do fix this problem ?!
Try this download function instead :
<?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);
}
Your ZIP file is most likely corrupted because your PHP script contains white space after closing ?>
tag which pollutes ZIP content. To solve this, remove PHP closing tag ?>
from your script that function download()
is part of (also check if you do not have leading white-spaces, placed before opening <?php
tag too) and your issue should be gone. If you include other scripts, check them for spaces too. In general ?>
tag should not be used, unless you are sure you need it it for known reason (which is very rare case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With