/ Gists / PHP

Gists - PHP

On gists

PHP: Unzip folder

PHP

unzip-folder.php #

<?
    $extract_dir = "./sprites/";
    $extract_file = "sprites.zip";
    $zip = new ZipArchive;
    $res = $zip->open($extract_file);
    if ($res === TRUE) {
    $zip->extractTo($extract_dir);
    $zip->close();
    echo "OK";
    } else {
    echo "NOK";
    }

?>

On gists

PHP: Zip folder

PHP

zip-folder.php #

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