Wordpress can't use ZipArchive
Im currently developing a site where customers can download brand images like packshots. Ive made a custom cart where the client should be able to download all images added to the cart using ZipArchive. But it dosent seem to work as easy if it was not WordPress(as it usually is).
My code:
$files = array('test.jpg', 'test2.jpg');
$zipname = 'images.zip';
$zip = new ZipArchive;
$zip-open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip-addFile($file);
}
$zip-close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
At first i had Error:
Warning: Cannot modify header information - headers already sent by (output started at
but i managed fixing this using the init action.
The second problem was that no zip was downloaded.
My question is if anyone here have worked with ZipArchive in WP that would be able to show some samplecode. Or have any tips that may work.
Thanks.
Topic ziparchive headers php plugin-development Wordpress
Category Web