Kcko
10/10/2013 - 1:40 PM

PHP: Zip folder

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);