Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my class to work with Zip.</p> <p>I have no trouble with it on PHP 5.3.8.</p> <pre><code>&lt;?php /** * @author Andrew Zavadsky &lt;zaffaccky@gmail.com&gt; * @class Zip * @description Class for manipulation ZIP (creating, unzipping) */ class Zip { private $zip = null; public function __construct($src) { $this-&gt;zip = new ZipArchive(); if (!file_exists($src)) $r = $this-&gt;zip-&gt;open($src, ZipArchive::CREATE); else $r = $this-&gt;zip-&gt;open($src); } public function addFromString($as, $text) { $this-&gt;zip-&gt;addFromString($as, $text); return $this; } public function addFile($as, $src = null) { if ($src &amp;&amp; file_exists($src)) $this-&gt;zip-&gt;addFile($src, $as); else $this-&gt;zip-&gt;addFromString($as, ''); return $this; } public function unzip($to, array $files = array()) { if (!file_exists($to)) mkdir($to); if (!is_writable($to) || !is_dir($to)) throw new Exception(sprintf('Target directory %s is not directory or not for writing', $to)); if (count($files)) $this-&gt;zip-&gt;extractTo($to, $files); else $this-&gt;zip-&gt;extractTo($to); $this-&gt;zip-&gt;close(); return $this; } public function addFolder($as, $src = null) { $as = trim($as, '\\/'); $this-&gt;zip-&gt;addEmptyDir($as); if ($src &amp;&amp; file_exists($src) &amp;&amp; is_dir($src)) $this-&gt;addFiles($src, $as); return $this; } private function addFiles($from, $to = '', $recursive = true) { $from = rtrim($from, '\\/'); $to = trim($to, '\\/'); if (!is_dir($from)) throw new Exception(sprintf('Can\'t add files from folder %s', $from)); else $this-&gt;zip-&gt;addEmptyDir($to); foreach (scandir($from) as $i =&gt; $f) { if ($i &lt;= 1) continue; if (is_dir($file = $from . DIRECTORY_SEPARATOR . $f) &amp;&amp; $recursive) $this-&gt;addFiles($file, $to . DIRECTORY_SEPARATOR . $f, $recursive); else $this-&gt;addFile($to ? $to . DIRECTORY_SEPARATOR . $f : $f, $file); } return $this; } } </code></pre> <p>Try it, you need $zip->unzip($to, $options);</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload