src/Filesystem.php
/**
     * Zip a directory and all of its contents into a zip file.
     * @param string $sourceFolder - path to the folder we wish to zip up.
     * @param string $dest - path and name to give the zipfile 
     *                       e.g. (/tmp/my_zip.zip)
     * @param bool $deleteOnComplete - specify false if you want to keep the 
     *                                 original uncompressed files after they 
     *                                 have been zipped.
     */
Zip a directory and all of its contents into a zip file.
@param string $sourceFolder - path to the folder we wish to zip up.
@param string $dest - path and name to give the zipfile
e.g. (/tmp/my_zip.zip)
@param bool $deleteOnComplete - specify false if you want to keep the
original uncompressed files after they
have been zipped.
Zip a directory and all of its contents into a zip file . @param string $sourceFolder - path to the folder we wish to zip up . @param string $dest - path and name to give the zipfile e . g . ( / tmp / my_zip . zip ) @param bool $deleteOnComplete - specify false if you want to keep the original uncompressed files after they have been zipped .
public static function zipDir($sourceFolder, $dest, $deleteOnComplete=true)
    {
        if (!extension_loaded('zip') )
        {
            throw new \Exception("Your PHP does not have the zip extesion.");
        }
        if (!file_exists($sourceFolder)) 
        {
            throw new \Exception("Cannot zip non-existent folder");
        }
        $rootPath = realpath($sourceFolder);
        $zip = new \ZipArchive();
        $zip->open($dest, \ZipArchive::CREATE);
        $files = self::getDirContents($sourceFolder, true, true, true);
        $baseDir = basename($sourceFolder);
        $zip->addEmptyDir($baseDir);
        foreach ($files as $name => $filepath) 
        {
            $relativePath = str_replace($sourceFolder, $baseDir, $filepath);
            $zip->addFile($filepath, $relativePath);
        }
        $zip->close();
        if ($deleteOnComplete)
        {
            self::deleteDir($sourceFolder);
        }
    }
public static function zipDir ( $ sourceFolder , $ dest , $ deleteOnComplete = true ) { if ( ! extension_loaded ( 'zip' ) ) { throw new \ Exception ( " Your PHP does not have the zip extesion. " ) ; } if ( ! file_exists ( $ sourceFolder ) ) { throw new \ Exception ( " Cannot zip non-existent folder " ) ; } $ rootPath = realpath ( $ sourceFolder ) ; $ zip = new \ ZipArchive ( ) ; $ zip -> open ( $ dest , \ ZipArchive :: CREATE ) ; $ files = self :: getDirContents ( $ sourceFolder , true , true , true ) ; $ baseDir = basename ( $ sourceFolder ) ; $ zip -> addEmptyDir ( $ baseDir ) ; foreach ( $ files as $ name => $ filepath ) { $ relativePath = str_replace ( $ sourceFolder , $ baseDir , $ filepath ) ; $ zip -> addFile ( $ filepath , $ relativePath ) ; } $ zip -> close ( ) ; if ( $ deleteOnComplete ) { self :: deleteDir ( $ sourceFolder ) ; } }
Zip a directory and all of its contents into a zip file.
Zip a directory and all of its contents into a zip file .
#$filePath = $file->getRealPath(); # Delete all files from "delete list"