Class luya\yii\helpers\ZipHelper

Inheritanceluya\yii\helpers\ZipHelper
Subclassesluya\helpers\ZipHelper
Available since version1.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

Hide inherited methods

Method Description Defined By
dir() Zip a folder (include itself). luya\yii\helpers\ZipHelper

Method Details

Hide inherited methods

dir() public static method

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;
}