-
-
Save dgoze/19bd0cf0c79dc5ee67a96228e7c3cd0d to your computer and use it in GitHub Desktop.
Add Files to Zip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$files = array('file1.txt', 'file2.csv', 'file3.png'); | |
$zip = new ZipArchive(); | |
$zip_name = "out/" . time() . ".zip"; // Zip name | |
$zip->open($zip_name, ZipArchive::CREATE); | |
foreach ($files as $path) { | |
if (file_exists($path)) { | |
$zip->addFromString(basename($path), file_get_contents($path)); | |
} else { | |
echo"file does not exist"; | |
} | |
} | |
$zip->close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment