Skip to content

Instantly share code, notes, and snippets.

@Bolinha1
Last active June 16, 2016 03:08
Show Gist options
  • Save Bolinha1/06ba0104476839a1a53afcd7ebd0e13e to your computer and use it in GitHub Desktop.
Save Bolinha1/06ba0104476839a1a53afcd7ebd0e13e to your computer and use it in GitHub Desktop.
<?php
require __DIR__."/zip/Zip.php";
$zip = new Zip();
var_dump($zip->zipar("test", "test/test.zip", "archive"));
var_dump($zip->zipar("test-1", "test-1/test1.zip", "test"));
var_dump($zip->zipar("test-2", "test-2/test2.zip", "test-1"));
var_dump($zip->zipar("test-3", "test-3/test3.zip", "test-2"));
<?php
class Zip
{
private $pathFile;
private $fileZip;
private $dirCurrent;
public function zipar($pathFile, $fileZip, $dirCurrent)
{
$this->dirCurrent = $dirCurrent;
$this->pathFile = $pathFile;
$this->fileZip = $fileZip;
$zip = new ZipArchive();
chdir($this->dirCurrent);
$zip->open($this->fileZip, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($pathFile),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file)
{
if(!$file->isDir())
$zip->addFile($file);
}
$zip->close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment