protected static function createArchiveForPear(array $files, $archiveFileName)
    {
        $compression = null;
        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $compression = 'gz';
                break;
            case 'bz2':
            case 'tbz2':
                $compression = 'bz2';
                break;
            case 'xz':
                $compression = 'lzma2';
                break;
            case 'z':
                $tar_aname = 'compress.lzw://' . $archiveFileName;
                break;
        }

        if (isset($tar_aname))
            $tar = new Archive_Tar($tar_aname, $compression);
        else
            $tar = new Archive_Tar($archiveFileName, $compression);

        foreach ($files  as $localName => $filename) {
            $remove_dir = dirname($filename);
            $add_dir = dirname($localName);

            if (is_null($filename)) {
                if ($tar->addString($localName, '') === false)
                    throw new Exception('Error when adding directory '.$localName.' to archive');
            } else {
                if ($tar->addModify($filename, $add_dir, $remove_dir) === false)
                    throw new Exception('Error when adding file '.$filename.' to archive');
            }
        }
        $tar = null;

        return count($files);
    }
protected static function createArchiveForPear(array $files, $archiveFileName)
    {
        $compression = null;
        switch (strtolower(pathinfo($archiveFileName, PATHINFO_EXTENSION))) {
            case 'gz':
            case 'tgz':
                $compression = 'gz';
                break;
            case 'bz2':
            case 'tbz2':
                $compression = 'bz2';
                break;
            case 'xz':
                $compression = 'lzma2';
                break;
            case 'z':
                $tar_aname = 'compress.lzw://' . $archiveFileName;
                break;
        }

        if (isset($tar_aname))
            $tar = new Archive_Tar($tar_aname, $compression);
        else
            $tar = new Archive_Tar($archiveFileName, $compression);

        foreach ($files  as $localName => $filename) {
            $remove_dir = dirname($filename);
            $add_dir = dirname($localName);

            if (is_null($filename)) {
                if ($tar->addString($localName, '') === false)
                    throw new Exception('Error when adding directory '.$localName.' to archive');
            } else {
                if ($tar->addModify($filename, $add_dir, $remove_dir) === false)
                    throw new Exception('Error when adding file '.$filename.' to archive');
            }
        }
        $tar = null;

        return count($files);
    }
protected static function createArchiveForPear ( array $ files , $ archiveFileName ) { $ compression = null ; switch ( strtolower ( pathinfo ( $ archiveFileName , PATHINFO_EXTENSION ) ) ) { case 'gz' : case 'tgz' : $ compression = 'gz' ; break ; case 'bz2' : case 'tbz2' : $ compression = 'bz2' ; break ; case 'xz' : $ compression = 'lzma2' ; break ; case 'z' : $ tar_aname = 'compress.lzw://' . $ archiveFileName ; break ; } if ( isset ( $ tar_aname ) ) $ tar = new Archive_Tar ( $ tar_aname , $ compression ) ; else $ tar = new Archive_Tar ( $ archiveFileName , $ compression ) ; foreach ( $ files as $ localName => $ filename ) { $ remove_dir = dirname ( $ filename ) ; $ add_dir = dirname ( $ localName ) ; if ( is_null ( $ filename ) ) { if ( $ tar -> addString ( $ localName , '' ) === false ) throw new Exception ( 'Error when adding directory ' . $ localName . ' to archive' ) ; } else { if ( $ tar -> addModify ( $ filename , $ add_dir , $ remove_dir ) === false ) throw new Exception ( 'Error when adding file ' . $ filename . ' to archive' ) ; } } $ tar = null ; return count ( $ files ) ; }
Creates an archive via Pear library
@param array $files
@param $archiveFileName
@return bool|int
@throws Exception
Creates an archive via Pear library