PHP code example of xp-framework / zip

1. Go to this page and download the library: Download xp-framework/zip library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xp-framework / zip example snippets


use io\archive\zip\{ZipFile, ZipDirEntry, ZipFileEntry};
use io\File;

$z= ZipFile::create(new File('dist.zip'));

// Add a directory
$dir= $z->add(new ZipDirEntry('META-INF'));

// Add a file
$file= $z->add(new ZipFileEntry($dir, 'version.txt'));
$file->out()->write($contents);

// Close
$z->close();

use io\archive\zip\ZipFile;
use io\streams\Streams;
use io\File;

$z= ZipFile::open(new File('dist.zip'));
foreach ($z->entries() as $entry) {
  if ($entry->isDirectory()) {
    // Create dir
  } else {
    // Extract
    Streams::readAll($entry->in());
  }
}