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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -