Skip to content

Instantly share code, notes, and snippets.

@vovadocent
Created January 11, 2017 09:47
Show Gist options
  • Save vovadocent/8103622fed9a84f59db0d6183ce1fa7f to your computer and use it in GitHub Desktop.
Save vovadocent/8103622fed9a84f59db0d6183ce1fa7f to your computer and use it in GitHub Desktop.
Add Files to Zip
<?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