Class luya\yii\helpers\ZipHelper
Inheritance | luya\yii\helpers\ZipHelper |
---|---|
Subclasses | luya\helpers\ZipHelper |
Available since version | 1.0.0 |
Source Code | https://github.com/luyadev/yii-helpers/blob/master/src/helpers/ZipHelper.php |
Helper methods when dealing with ZIP Archives.
Public Methods
Method | Description | Defined By |
---|---|---|
dir() | Zip a folder (include itself). | luya\yii\helpers\ZipHelper |
Method Details
Zip a folder (include itself).
ZipHelper::dir('/path/to/sourceDir', '/path/to/out.zip');
public static void dir ( $sourcePath, $outZipPath ) | ||
$sourcePath | string |
Path of directory to be zip. |
$outZipPath | string |
Path of output zip file. |
public static function dir($sourcePath, $outZipPath)
{
$pathInfo = pathInfo($sourcePath);
$parentPath = $pathInfo['dirname'];
$dirName = $pathInfo['basename'];
$z = new ZipArchive();
$z->open($outZipPath, ZIPARCHIVE::CREATE);
$z->addEmptyDir($dirName);
self::folderToZip($sourcePath, $z, strlen("$parentPath/"));
$z->close();
return true;
}