Skip to content

Instantly share code, notes, and snippets.

@mariordev
Last active January 28, 2016 03:58
Show Gist options
  • Save mariordev/92ce8fa2fdc270734e13 to your computer and use it in GitHub Desktop.
Save mariordev/92ce8fa2fdc270734e13 to your computer and use it in GitHub Desktop.
Zip a File in PHP/Laravel
$temp_files[] = self::saveJsonFile($account_id . '_accounts.json', $data);
// Zip it all up!
$storage = storage_path() . '/archive/';
$zip_file = $account_id . '_archive_' . time() . '.zip';
$zip = new ZipArchive;
$open = $zip->open($storage . $zip_file, ZipArchive::CREATE);
if ($open === true) {
foreach ($temp_files as $file) {
$zip->addFile($file);
}
$zip->close();
} else {
throw Exception;
}
// Clean up.
File::delete($temp_files);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment