Class luya\helpers\ZipHelper
| Inheritance | luya\helpers\ZipHelper ยป luya\yii\helpers\ZipHelper |
|---|---|
| Available since version | 1.0.0 |
| Source Code | https://github.com/luyadev/luya/blob/master/core/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
Defined in: luya\yii\helpers\ZipHelper::dir()
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;
}