note 112195 added to class.ziparchive

From: Date: Thu, 16 May 2013 08:23:28 +0000
Subject: note 112195 added to class.ziparchive
Groups: php.notes 
Request: Send a blank email to php-notes+get-194818@lists.php.net to get a copy of this message
Simple class xZip to zip big folders into multiple parts and unzip multi zip files at once. <?php class xZip { public function __construct() {} private function _rglobRead($source, &$array = array()) { if (!$source || trim($source) == "") { $source = "."; } foreach ((array) glob($source . "/*/") as $key => $value) { $this->_rglobRead(str_replace("//", "/", $value), $array); } foreach ((array) glob($source . "*.*") as $key => $value) { $array[] = str_replace("//", "/", $value); } } private function _zip($array, $part, $destination) { $zip = new ZipArchive; @mkdir($destination, 0777, true); if ($zip->open(str_replace("//", "/", "{$destination}/partz{$part}.zip"), ZipArchive::CREATE)) { foreach ((array) $array as $key => $value) { $zip->addFile($value, str_replace(array("../", "./"), NULL, $value)); } $zip->close(); } } public function zip($limit = 500, $source = NULL, $destination = "./") { if (!$destination || trim($destination) == "") { $destination = "./"; } $this->_rglobRead($source, $input); $maxinput = count($input); $splitinto = (($maxinput / $limit) > round($maxinput / $limit, 0)) ? round($maxinput / $limit, 0) + 1 : round($maxinput / $limit, 0); for($i = 0; $i < $splitinto; $i ++) { $this->_zip(array_slice($input, ($i * $limit), $limit, true), $i, $destination); } unset($input); return; } public function unzip($source, $destination) { @mkdir($destination, 0777, true); foreach ((array) glob($source . "/*.zip") as $key => $value) { $zip = new ZipArchive; if ($zip->open(str_replace("//", "/", $value)) === true) { $zip->extractTo($destination); $zip->close(); } } } public function __destruct() {} } //$zip = new xZip; //$zip->zip(500, "images/", "images_zip/"); //$zip->unzip("images_zip/", "images/"); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 196.20.228.188 ---- Manual Page -- http://php.net/manual/en/class.ziparchive.php Edit -- https://master.php.net/note/edit/112195 Del: integrated -- https://master.php.net/note/delete/112195/integrated Del: useless -- https://master.php.net/note/delete/112195/useless Del: bad code -- https://master.php.net/note/delete/112195/bad+code Del: spam -- https://master.php.net/note/delete/112195/spam Del: non-english -- https://master.php.net/note/delete/112195/non-english Del: in docs -- https://master.php.net/note/delete/112195/in+docs Del: other reasons-- https://master.php.net/note/delete/112195 Reject -- https://master.php.net/note/reject/112195 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194818) next »