Things You'll Need:
- Files to zip Webserver with PHP and the ZIP extension installed PHP code editor
-
Step 1
Upload your files to your web server into a common directory. Make sure this directory cannot be directly accessed by users by placing it outside the "www" folder on your server. That way, PHP will still be able to access the files but browsers won't.
-
Step 2
Create a new PHP script called "zipdownload.php" that is accessible by the web server. Your scripts will redirect users to this page when they need to download the dynamic ZIP archive.
-
Step 3
Create a new ZipArchive object in zipdownload.php by writing "$zip = new ZipArchive();". This will create a new container for your ZIP files and assign it to a variable, named "$zip." Use the "$zip->open" method to create a particular ZIP file in your servers' temp directory. See the Resources section for more details.
-
Step 4
Add files to your new ZIP archive using the "$zip->addFromString" method. This will encode a new file and add it to the ZIP archive. Repeat this as many times as is necessary. See the resources for more details.
-
Step 5
Close the file when you have finished adding files to your ZIP archive using the "$zip->close" method. You may now mail it to users or output it to the browser using PHP's "readfile" function.
-
Step 6
Delete the archive when you have finished with it by calling the "unlink" function on the file.














