PHP code example of smuuf / zip-reader
1. Go to this page and download the library: Download smuuf/zip-reader 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/ */
smuuf / zip-reader example snippets
use \Smuuf\StrictObject;
use \Smuuf\ZipReader\ZippedDir;
use \Smuuf\ZipReader\ZippedFile;
ZipReader('/some/zipped/file.zip');
// This returns a dict array of items that are present in the root directory
// of the zip. For example:.
// [
// 'dir_a/' => ZippedDir object,
// 'dir_b/' => ZippedDir object,
// 'some_file_a.txt' => ZippedFile object,
// ]
$entries = $zipReader->getEntries();
// When browsing, directory path must have a trailing slash.
$item = $zipReader->browse('dir_a/'); // Instance of ZippedDir.
$item = $zipReader->browse('not_present_dir/'); // null
$item = $zipReader->browse('some_file_a.txt'); // Instance of ZippedFile.
$item = $zipReader->browse('not_present_dir/'); // null
// You can do nested browsing.
$dir = $zipReader->browse('dir_a/inner_dir/'); // Instance of ZippedDir.
$somefile = $zipReader->browse('dir_a/inner_dir/some_file.txt'); // Instance of ZippedFile.
// You can also browse further in the ZippedDir object.
// This will return ZippedFile that represents 'dir_a/inner_dir/some_other_file.txt'.
$someOtherFile = $dir->browse('some_other_file.txt');
// You can get contents of zipped file (done lazily).
$bytes = $someOtherFile->read();
// You can get stat array of a zipped file or a dir (done lazily).
// See https://www.php.net/manual/en/ziparchive.statname.php to see what
// items the stat array can returns.
$fileStat = $someOtherFile->stat();
$dirStat = $dir->stat();