-
-
Save torbentschechne/bdcdde5866bbf64a9def25802842016d to your computer and use it in GitHub Desktop.
Create PHP .zip file
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
/** | |
* @param array $contents | |
* @param bool $overwrite | |
* @return bool | |
*/ | |
public function create_zip($contents = array(), $overwrite = false) { | |
$zip_filename = Shopware()->DocPath() . "files/documents" . "/jett_mce_support_".time().".zip"; | |
if (file_exists($zip_filename) && !$overwrite) { return false; } | |
if ($contents) { | |
$zip = new \ZipArchive(); | |
if($zip->open($zip_filename, $overwrite ? \ZIPARCHIVE::OVERWRITE : \ZIPARCHIVE::CREATE) !== true) { | |
return false; | |
} | |
foreach($contents as $k => $content) { | |
$zip->addFromString($k.'.csv', $content); | |
} | |
$zip->close(); | |
return ['status' => file_exists($zip_filename), 'file' => $zip_filename]; | |
} else { | |
return ['status' => false]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment