Last active
December 25, 2015 04:39
-
-
Save Kcko/6918489 to your computer and use it in GitHub Desktop.
PHP: Zip folder
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
<? | |
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