Last active
June 16, 2016 03:08
-
-
Save Bolinha1/06ba0104476839a1a53afcd7ebd0e13e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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