Create a Zip archive
How do you create a compressed archive using PHP?
This example will show you how you create a ZIP file with the file syou want to have for your users to download.
You can f.ex use this, if your users are to download a huge bunch of files, lik images. Then you can zip them on the fly, and let your user download a single Zip file instead of havign to download them all, one by one.
HTML
<HTML><BODY>
<TABLE>
<FORM METHOD='POST' ACTION='#'>
<TR>
<TD>Click here to create ZIP archive: </TD>
<TD><INPUT TYPE='submit' NAME='dozip' VALUE='Create zip archive'></TD>
</TR></FORM>
</TABLE>
</BODY></HTML>
PHP
<?php
if (isset($_POST['dozip'])) {
$thedir = getcwd();
$zippath = $thedir . "/" . "zippo.zip";
$zip = new ZipArchive();
if ($zip->open($zippath, ZipArchive::CREATE)) {
$zip->addFile("file_1.txt");
$zip->addFile("file_2.txt");
$zip->addFile("file_3.txt");
}
$zip->close();
echo "Finished"; exit();
}
?>