Class luya\helpers\ZipHelper

Inheritanceluya\helpers\ZipHelper » luya\yii\helpers\ZipHelper
Available since version1.0.0
Source Code https://github.com/luyadev/luya/blob/master/core/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

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