public static function extractZipArchive($file, $destinationDir, $createDir = false)
    {
        if (!file_exists($destinationDir)) {
            if (false === $createDir) {
                throw new ApplicationException(sprintf("Destination directory does not exist: %s .", $destinationDir));
            }

            $folderCreation = mkdir($destinationDir, 0777, true);
            if (false === $folderCreation) {
                throw new ApplicationException(sprintf("Destination directory cannot be created: %s .", $destinationDir));
            }

            if (!is_readable($destinationDir)) {
                throw new ApplicationException(sprintf("Destination directory is not readable: %s .", $destinationDir));
            }
        } elseif (!is_dir($destinationDir)) {
            throw new ApplicationException(sprintf("Destination directory cannot be created as a file with that name already exists: %s .", $destinationDir));
        }

        $archive = new ZipArchive();

        if (false === $archive->open($file)) {
            throw new ApplicationException(sprintf("Could not open archive: %s .", $archive));
        }
        try {
            $archive->extractTo($destinationDir);
        } catch (\Exception $e) {
            throw new ApplicationException(sprintf("Could not extract archive from path: %s .", $file));
        }

        $archive->close();
    }
public static function extractZipArchive($file, $destinationDir, $createDir = false)
    {
        if (!file_exists($destinationDir)) {
            if (false === $createDir) {
                throw new ApplicationException(sprintf("Destination directory does not exist: %s .", $destinationDir));
            }

            $folderCreation = mkdir($destinationDir, 0777, true);
            if (false === $folderCreation) {
                throw new ApplicationException(sprintf("Destination directory cannot be created: %s .", $destinationDir));
            }

            if (!is_readable($destinationDir)) {
                throw new ApplicationException(sprintf("Destination directory is not readable: %s .", $destinationDir));
            }
        } elseif (!is_dir($destinationDir)) {
            throw new ApplicationException(sprintf("Destination directory cannot be created as a file with that name already exists: %s .", $destinationDir));
        }

        $archive = new ZipArchive();

        if (false === $archive->open($file)) {
            throw new ApplicationException(sprintf("Could not open archive: %s .", $archive));
        }
        try {
            $archive->extractTo($destinationDir);
        } catch (\Exception $e) {
            throw new ApplicationException(sprintf("Could not extract archive from path: %s .", $file));
        }

        $archive->close();
    }
public static function extractZipArchive ( $ file , $ destinationDir , $ createDir = false ) { if ( ! file_exists ( $ destinationDir ) ) { if ( false === $ createDir ) { throw new ApplicationException ( sprintf ( "Destination directory does not exist: %s ." , $ destinationDir ) ) ; } $ folderCreation = mkdir ( $ destinationDir , 0777 , true ) ; if ( false === $ folderCreation ) { throw new ApplicationException ( sprintf ( "Destination directory cannot be created: %s ." , $ destinationDir ) ) ; } if ( ! is_readable ( $ destinationDir ) ) { throw new ApplicationException ( sprintf ( "Destination directory is not readable: %s ." , $ destinationDir ) ) ; } } elseif ( ! is_dir ( $ destinationDir ) ) { throw new ApplicationException ( sprintf ( "Destination directory cannot be created as a file with that name already exists: %s ." , $ destinationDir ) ) ; } $ archive = new ZipArchive ( ) ; if ( false === $ archive -> open ( $ file ) ) { throw new ApplicationException ( sprintf ( "Could not open archive: %s ." , $ archive ) ) ; } try { $ archive -> extractTo ( $ destinationDir ) ; } catch ( \ Exception $ e ) { throw new ApplicationException ( sprintf ( "Could not extract archive from path: %s ." , $ file ) ) ; } $ archive -> close ( ) ; }
Extracts a zip archive into a specified directory

@param  string                                        $file           zip         archive file
@param  string                                        $destinationDir where the files will be extracted to
@param  bool                                          $createDir      should destination dir be created if it doesn't exist
@throws \BackBee\Utils\Exception\ApplicationException Occures if there is an issue with $destinationDir
Extracts a zip archive into a specified directory