Created
January 11, 2017 09:47
-
-
Save vovadocent/8103622fed9a84f59db0d6183ce1fa7f to your computer and use it in GitHub Desktop.
Add Files to Zip
This file contains 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