https://dev.webpages.dk/  
 
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.

 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(); 
} 
?>
Icons made by Freepik from www.flaticon.com This page is about how to create a ZIP archive, on the fly, using PHP.
10:59:42