PHP How to create a ZIP Archive
How to create a ZIP Archive:

Here you are shown how to create a ZIP archive. This can be useful if let's say that you want your user to download some files, and they are some that she picks from a list (so its a dynamic collection of different files, and therefor maybe not a good idea, to be a pre-made Zip package). Then you can pack the files on the fly and let your user download that ZIP package. Maybe remember to delete that ZIP file again, after use. :-)

 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.


<TD>Click here to create ZIP archive: </TD> 
<TD><INPUT TYPE='submit' NAME='dozip' VALUE='Create zip archive'></TD> 


if (isset($_POST['dozip']))  { 
    $thedir = getcwd(); 
    $zippath = $thedir . "/" . "";	 

    $zip = new ZipArchive(); 
    if ($zip->open($zippath, ZipArchive::CREATE)) {	 

    echo "Finished"; exit(); 
Icons made by Freepik from This page is about how to create a ZIP archive, on the fly, using PHP.