Last active
January 28, 2016 03:58
-
-
Save mariordev/92ce8fa2fdc270734e13 to your computer and use it in GitHub Desktop.
Zip a File in PHP/Laravel
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
$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