Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active December 25, 2015 04:39
Show Gist options
  • Save Kcko/6918489 to your computer and use it in GitHub Desktop.
Save Kcko/6918489 to your computer and use it in GitHub Desktop.
PHP: Zip folder
<?
class zipuj_helper
{
protected $jmeno_zipu;
protected $root;
protected $zip;
public function __construct($root = ".", $jmeno_zipu = "zip.zip")
{
$this->root = $root;
$this->jmeno_zipu = $jmeno_zipu;
$this->zip = new ZipArchive();
$this->zip->open($this->jmeno_zipu, ZIPARCHIVE::CREATE);
$this->nactiAdr();
$this->uloz();
}
public function nactiAdr($cesta = "")
{
$hn = scandir($this->root.$cesta);
foreach ($hn as $file)
{
if ($file == "." || $file == "..")
{
continue;
}
if (is_dir($this->root.$cesta."/".$file))
{
$this->zip->addEmptyDir($cesta."/".$file);
$this->nactiAdr($cesta."/".$file);
}
else
{
$this->zip->addFile($this->root.$cesta."/".$file, $cesta."/".$file);
}
}
}
public function uloz()
{
$this->zip->close();
}
}
// use
$filename = 'prilohy__' . date('YmdHis') . '.zip';
$zalohuj = new zipuj_helper('./storage/application/', './storage/application-zip/' . $filename);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment