1. Go to this page and download the library: Download wp-php-toolkit/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/ */
wp-php-toolkit / zip example snippets
WordPress\ByteStream\MemoryPipe;
use WordPress\ByteStream\ReadStream\FileReadStream;
use WordPress\ByteStream\WriteStream\FileWriteStream;
use WordPress\Zip\FileEntry;
use WordPress\Zip\ZipDecoder;
use WordPress\Zip\ZipEncoder;
use WordPress\Zip\ZipFilesystem;
$path = tempnam( sys_get_temp_dir(), 'demo' ) . '.zip';
$out = FileWriteStream::from_path( $path, 'truncate' );
$enc = new ZipEncoder( $out );
$enc->append_file( new FileEntry( array(
'path' => 'readme.txt',
'compression_method' => ZipDecoder::COMPRESSION_NONE,
'body_reader' => new MemoryPipe( 'Hello from inside the zip.' ),
) ) );
$enc->close();
$out->close_writing();
$zip = ZipFilesystem::create( FileReadStream::from_path( $path ) );
echo $zip->get_contents( 'readme.txt' );
WordPress\ByteStream\MemoryPipe;
use WordPress\ByteStream\ReadStream\FileReadStream;
use WordPress\ByteStream\WriteStream\FileWriteStream;
use WordPress\Zip\FileEntry;
use WordPress\Zip\ZipDecoder;
use WordPress\Zip\ZipEncoder;
use WordPress\Zip\ZipFilesystem;
$path = tempnam( sys_get_temp_dir(), 'book' ) . '.epub';
$out = FileWriteStream::from_path( $path, 'truncate' );
$enc = new ZipEncoder( $out );
// 1) The mimetype entry MUST be first and stored uncompressed.
$enc->append_file( new FileEntry( array(
'path' => 'mimetype',
'compression_method' => ZipDecoder::COMPRESSION_NONE,
'body_reader' => new MemoryPipe( 'application/epub+zip' ),
) ) );
$container = <<<'XML'
<?xml version="1.0"