public static function createZip(String $path, Array $data) : Bool
    {
        $path    = Info::rpath($path);
        $zip     = new ZipArchive;
        $zipPath = Base::suffix($path, ".zip");

        if( file_exists($zipPath) )
        {
            unlink($zipPath);
        }

        if( ! is_dir($pathDirName = Info::pathInfo($path, 'dirname')) )
        {
            mkdir($pathDirName);
        }

        if( $zip->open($zipPath, ZipArchive::CREATE) !== true )
        {
            return false;
        }

        $status = '';

        if( ! empty($data) ) foreach( $data as $key => $val )
        {
            if( is_numeric($key) )
            {
                $file = $val;
                $fileName = NULL;
            }
            else
            {
                $file = $key;
                $fileName = $val;
            }

            if( is_dir($file) )
            {
                $allFiles = FileList::allFiles($file, true);

                foreach( $allFiles as $f )
                {
                    $status = $zip->addFile($f, $f);
                }
            }
            else
            {
                $status = $zip->addFile($file, $fileName);
            }
        }

        return $zip->close();
    }
public static function createZip(String $path, Array $data) : Bool
    {
        $path    = Info::rpath($path);
        $zip     = new ZipArchive;
        $zipPath = Base::suffix($path, ".zip");

        if( file_exists($zipPath) )
        {
            unlink($zipPath);
        }

        if( ! is_dir($pathDirName = Info::pathInfo($path, 'dirname')) )
        {
            mkdir($pathDirName);
        }

        if( $zip->open($zipPath, ZipArchive::CREATE) !== true )
        {
            return false;
        }

        $status = '';

        if( ! empty($data) ) foreach( $data as $key => $val )
        {
            if( is_numeric($key) )
            {
                $file = $val;
                $fileName = NULL;
            }
            else
            {
                $file = $key;
                $fileName = $val;
            }

            if( is_dir($file) )
            {
                $allFiles = FileList::allFiles($file, true);

                foreach( $allFiles as $f )
                {
                    $status = $zip->addFile($f, $f);
                }
            }
            else
            {
                $status = $zip->addFile($file, $fileName);
            }
        }

        return $zip->close();
    }
public static function createZip ( String $ path , Array $ data ) : Bool { $ path = Info :: rpath ( $ path ) ; $ zip = new ZipArchive ; $ zipPath = Base :: suffix ( $ path , ".zip" ) ; if ( file_exists ( $ zipPath ) ) { unlink ( $ zipPath ) ; } if ( ! is_dir ( $ pathDirName = Info :: pathInfo ( $ path , 'dirname' ) ) ) { mkdir ( $ pathDirName ) ; } if ( $ zip -> open ( $ zipPath , ZipArchive :: CREATE ) !== true ) { return false ; } $ status = '' ; if ( ! empty ( $ data ) ) foreach ( $ data as $ key => $ val ) { if ( is_numeric ( $ key ) ) { $ file = $ val ; $ fileName = NULL ; } else { $ file = $ key ; $ fileName = $ val ; } if ( is_dir ( $ file ) ) { $ allFiles = FileList :: allFiles ( $ file , true ) ; foreach ( $ allFiles as $ f ) { $ status = $ zip -> addFile ( $ f , $ f ) ; } } else { $ status = $ zip -> addFile ( $ file , $ fileName ) ; } } return $ zip -> close ( ) ; }
Create a zip file.

@param string $path
@param array  $data

@return bool
Create a zip file .