php - Zip and Download -
i use code zip , download files php browser start zip download, corrupt. when try open browser say's format file unknown or damaged.
any tip solve?
$files = array('1.png', '2.png'); $zipname = 'file.zip'; $zip = new ziparchive; $zip->open($zipname, ziparchive::create); foreach ($files $file) { $zip->addfile($file); } $zip->close(); header('content-type: application/zip'); header('content-disposition: attachment; filename=file.zip'); header('content-length: ' . filesize($zipfilename)); obclean(); flush(); readfile($zipname);
the problem in line:
header('content-length: ' . filesize($zipfilename)); obclean();
change to:
header('content-length: ' . filesize($zipname)); ob_clean();
Comments
Post a Comment