protected function extractArchive($archiveFile)
    {
        if ($archiveFile instanceof File) {
            if (!$archiveFile->exists()) {
                throw new \common_Exception('Unable to open archive ' . '/' . $archiveFile->getPrefix());
            }
            $tmpDir = \tao_helpers_File::createTempDir();
            $tmpFilePath = $tmpDir . uniqid('sharedStimulus-import') . '.zip';
            $tmpFile = fopen($tmpFilePath, 'w');
            $originalPackage = $archiveFile->readStream();
            stream_copy_to_stream($originalPackage, $tmpFile);
            fclose($originalPackage);
            fclose($tmpFile);

            $archiveFile = $tmpFilePath;
        }

        $archiveDir = \tao_helpers_File::createTempDir();
        $archiveObj = new \ZipArchive();

        if ($archiveFile instanceof File) {
            // get a local copy of zip
            $tmpName = \tao_helpers_File::concat([\tao_helpers_File::createTempDir(), $archiveFile->getBasename()]);
            if (($resource = fopen($tmpName, 'wb')) !== false) {
                stream_copy_to_stream($archiveFile->readStream(), $resource);
                fclose($resource);
            }

            $archiveFile = $tmpName;
        }

        $archiveHandle = $archiveObj->open($archiveFile);
        if (true !== $archiveHandle) {
            throw new \common_Exception('Unable to open archive ' . $archiveFile);
        }
        if (\tao_helpers_File::checkWhetherArchiveIsBomb($archiveObj)) {
            throw new \common_Exception(sprintf('Source "%s" seems to be a ZIP bomb', $archiveFile));
        }
        if (!$archiveObj->extractTo($archiveDir)) {
            $archiveObj->close();
            throw new \common_Exception('Unable to extract to ' . $archiveDir);
        }
        $archiveObj->close();

        if (isset($tmpFilePath) && file_exists($tmpFilePath)) {
            unlink($tmpFilePath);
        }
        if (isset($tmpDir) && file_exists($tmpDir)) {
            rmdir($tmpDir);
        }

        return $archiveDir;
    }
protected function extractArchive($archiveFile)
    {
        if ($archiveFile instanceof File) {
            if (!$archiveFile->exists()) {
                throw new \common_Exception('Unable to open archive ' . '/' . $archiveFile->getPrefix());
            }
            $tmpDir = \tao_helpers_File::createTempDir();
            $tmpFilePath = $tmpDir . uniqid('sharedStimulus-import') . '.zip';
            $tmpFile = fopen($tmpFilePath, 'w');
            $originalPackage = $archiveFile->readStream();
            stream_copy_to_stream($originalPackage, $tmpFile);
            fclose($originalPackage);
            fclose($tmpFile);

            $archiveFile = $tmpFilePath;
        }

        $archiveDir = \tao_helpers_File::createTempDir();
        $archiveObj = new \ZipArchive();

        if ($archiveFile instanceof File) {
            // get a local copy of zip
            $tmpName = \tao_helpers_File::concat([\tao_helpers_File::createTempDir(), $archiveFile->getBasename()]);
            if (($resource = fopen($tmpName, 'wb')) !== false) {
                stream_copy_to_stream($archiveFile->readStream(), $resource);
                fclose($resource);
            }

            $archiveFile = $tmpName;
        }

        $archiveHandle = $archiveObj->open($archiveFile);
        if (true !== $archiveHandle) {
            throw new \common_Exception('Unable to open archive ' . $archiveFile);
        }
        if (\tao_helpers_File::checkWhetherArchiveIsBomb($archiveObj)) {
            throw new \common_Exception(sprintf('Source "%s" seems to be a ZIP bomb', $archiveFile));
        }
        if (!$archiveObj->extractTo($archiveDir)) {
            $archiveObj->close();
            throw new \common_Exception('Unable to extract to ' . $archiveDir);
        }
        $archiveObj->close();

        if (isset($tmpFilePath) && file_exists($tmpFilePath)) {
            unlink($tmpFilePath);
        }
        if (isset($tmpDir) && file_exists($tmpDir)) {
            rmdir($tmpDir);
        }

        return $archiveDir;
    }
protected function extractArchive ( $ archiveFile ) { if ( $ archiveFile instanceof File ) { if ( ! $ archiveFile -> exists ( ) ) { throw new \ common_Exception ( 'Unable to open archive ' . '/' . $ archiveFile -> getPrefix ( ) ) ; } $ tmpDir = \ tao_helpers_File :: createTempDir ( ) ; $ tmpFilePath = $ tmpDir . uniqid ( 'sharedStimulus-import' ) . '.zip' ; $ tmpFile = fopen ( $ tmpFilePath , 'w' ) ; $ originalPackage = $ archiveFile -> readStream ( ) ; stream_copy_to_stream ( $ originalPackage , $ tmpFile ) ; fclose ( $ originalPackage ) ; fclose ( $ tmpFile ) ; $ archiveFile = $ tmpFilePath ; } $ archiveDir = \ tao_helpers_File :: createTempDir ( ) ; $ archiveObj = new \ ZipArchive ( ) ; if ( $ archiveFile instanceof File ) { // get a local copy of zip $ tmpName = \ tao_helpers_File :: concat ( [ \ tao_helpers_File :: createTempDir ( ) , $ archiveFile -> getBasename ( ) ] ) ; if ( ( $ resource = fopen ( $ tmpName , 'wb' ) ) !== false ) { stream_copy_to_stream ( $ archiveFile -> readStream ( ) , $ resource ) ; fclose ( $ resource ) ; } $ archiveFile = $ tmpName ; } $ archiveHandle = $ archiveObj -> open ( $ archiveFile ) ; if ( true !== $ archiveHandle ) { throw new \ common_Exception ( 'Unable to open archive ' . $ archiveFile ) ; } if ( \ tao_helpers_File :: checkWhetherArchiveIsBomb ( $ archiveObj ) ) { throw new \ common_Exception ( sprintf ( 'Source "%s" seems to be a ZIP bomb' , $ archiveFile ) ) ; } if ( ! $ archiveObj -> extractTo ( $ archiveDir ) ) { $ archiveObj -> close ( ) ; throw new \ common_Exception ( 'Unable to extract to ' . $ archiveDir ) ; } $ archiveObj -> close ( ) ; if ( isset ( $ tmpFilePath ) && file_exists ( $ tmpFilePath ) ) { unlink ( $ tmpFilePath ) ; } if ( isset ( $ tmpDir ) && file_exists ( $ tmpDir ) ) { rmdir ( $ tmpDir ) ; } return $ archiveDir ; }
Unzip archive from the upload form

@param string|File $archiveFile
@return string temporary directory zipfile was extracted to

@throws \common_Exception
Unzip archive from the upload form