PHP Classes

How Can PHP Extract a Zip File to a Folder on the Server While it Shows a Progress Bar on a Web Page Learning from the Example of the Class TZipHandler: Show progress of Zip file extraction on the server

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-02-25 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
aos-zip-extract 1.0.0Custom (specified...8.4Compression, AJAX, PHP 8
Description 

Author

This package can show progress of Zip file extraction on the server.

It provides an example script that calls the TZipHandler class to extract the files of a given ZIP file on the server side.

The script also implements a callback function that can show a progress bar on the page the current user is seeing to show the progress of the Zip file that is being extracted.

Innovation Award
PHP Programming Innovation award nominee
February 2026
Number 2
Zip files are used by many developers and users of websites and applications to distribute a list of archives and folders in a single file that is compressed to occupy less storage space.

Extracting a ZIP archive file may take a long time depending on the size of the file.

If the users waiting for the ZIP archive do not see if the archive is being extracted, they may think that the archive is not being extracted.

This package provides an example script to show how a PHP web application can extract a Zip archive on the server and show a progress bar on a web page to show how much of the archive was extracted on the server at each moment.

This way the users can see how much of the archive was extracted and how much remains to be extracted.

Manuel Lemos
Picture of Christos Drogidis
  Performance   Level  
Name: Christos Drogidis <contact>
Classes: 37 packages by
Country: Greece Greece
Age: ???
All time rank: 379423 in Greece Greece
Week rank: 5 Up1 in Greece Greece Up
Innovation award
Innovation award
Nominee: 21x

Winner: 4x

Instructions

Example

<?php
/**
 * @ASCOOS-NAME : Ascoos OS
 * @ASCOOS-VERSION : 1.0.0
 * @ASCOOS-SUPPORT : support@ascoos.com
 * @ASCOOS-BUGS : https://issues.ascoos.com
 *
 * @CLASS-METHOD-STUDY : TZipHandler::extractWithProgress()
 * @file : extractWithProgress.php
 * @test : callback that sends JSON progress to the browser
 *
 * @desc <English> It demonstrates the use of the extractWithProgress method, which sends JSON progress to the browser via a callback
 * @desc <Greek> ?????????? ??? ????? ??? ??????? extractWithProgress ??? ???? callback ??????? JSON progress ???? browser
 *
 * @since PHP 8.3.0
 */
declare(strict_types=1);
use
ASCOOS\OS\Kernel\Archives\TZipHandler;

session_start();

// <EN> We save the progress in the session so that Ajax can read it
// <EL> ???????????? ??? ?????? ?? session ??? ?? ??? ???????? ?? Ajax
function ajaxProgressCallback(int $current, int $total, string $entryName = ''): void {
   
$_SESSION['zip_progress'] = [
       
'current' => $current,
       
'total' => $total,
       
'percent' => $total > 0 ? round(($current / $total) * 100, 2) : 0,
       
'entry' => $entryName,
    ];
// session_write_close(); // ????????? ??? AJAX ?? ???????? ?? session
}


// <EN> Starting decompression (once)
// <EL> ???????? ???????????? (??? ????)
if (!isset($_SESSION['zip_started'])) {
   
$_SESSION['zip_started'] = true;
   
$zipHandler =& TZipHandler::getInstance();
   
$zipHandler->extractWithProgress('/path/to/archive.zip', '/path/to/target', 'ajaxProgressCallback');
}

// <EN> Endpoint to return the current progress
// <EL> Endpoint ??? ?? ?????????? ??? ???????? ??????
header('Content-Type: application/json');
echo
json_encode($_SESSION['zip_progress'] ?? ['current'=>0,'total'=>0,'percent'=>0,'entry'=>'']);
?>


Details

ZIP Extraction with Real-Time Progress (AJAX + PHP)

This is an example implementation of extracting a ZIP archive with live progress updates in the browser using AJAX, with progress stored in the PHP session.

It demonstrates the use of the extractWithProgress() method of the TZipHandler class from Ascoos OS.

Features

  • Real-time progress bar (percentage + current file name)
  • AJAX polling (no WebSocket required)
  • Progress stored in `$_SESSION`
  • jQuery interface
  • Handles empty archives & completion state

Requirements

  • PHP ? 8.3
  • Ascoos OS 1.0.0 or AWES 26 Pro
  • Sessions enabled
  • Write permissions on the extraction folder
  • jQuery

Installation

  1. Download or clone the repository
  2. Place the files on your web server
  3. Adjust the paths inside `extractWithProgress.php` to match your environment:

    $zipHandler->extractWithProgress(
        '/path/to/your/archive.zip',
        '/path/to/extraction/folder',
        'ajaxProgressCallback'
    );
    

Usage

  1. Open `extractWithProgress.html` in your browser
  2. Click Start Extract
  3. Watch the progress bar and file log update in real time

Example output:

Extracted: folder/config.ini
Extracted: images/logo.png
...
Completed!

How it works (simplified)

Browser ---> Click "Start" ---> AJAX polling every 1s ---> extractWithProgress.php
                                           |
                                           v
                                 reads $_SESSION['zip_progress']
                                           |
                                           v
                                 returns JSON ? updates bar & log

The extraction runs inside one long PHP request, while progress is stored in the session and read by lightweight AJAX calls.

License

AGL (Ascoos General License).

© 2025-2026 Ascoos OS


  Files folder image Files (6)  
File Role Description
Accessible without login Plain text file extractWithProgress.html Doc. HTML page to show the progress of the zip archive extraction.
Accessible without login Plain text file extractWithProgress.php Example Example script
Accessible without login Plain text file LICENSE-EL.md Lic. License text
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README-EL.md Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
Downloadaos-zip-extract-2026-02-25.zip 6KB
Downloadaos-zip-extract-2026-02-25.tar.gz
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Ascoos OS Download .zip .tar.gz Uses Ascoos OS Kernel Required
 Version Control Unique User Downloads  
 100%
Total:0
This week:0