PHP 8.5.0 Beta 1 available for testing

Voting

: one minus one?
(Example: nine)

The Note You're Voting On

AshleyDambra at live dot com
12 years ago
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/");
?>

<< Back to user notes page

To Top