PHP code example of cataphract / libarchive
1. Go to this page and download the library: Download cataphract/libarchive 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/ */
cataphract / libarchive example snippets
use libarchive\Archive;
use libarchive\EXTRACT_PERM;
use libarchive\EXTRACT_TIME;
$archive = new Archive('/path/to/archive.tar.gz', EXTRACT_PERM | EXTRACT_TIME);
chdir('/tmp/extract');
foreach ($archive as $entry) {
echo $entry->pathname . "\n";
$archive->extractCurrent($entry);
}
use libarchive\Archive;
$archive = new Archive('/path/to/archive.zip');
foreach ($archive as $entry) {
if ($entry->pathname === 'data.json') {
$stream = $archive->currentEntryStream();
$contents = stream_get_contents($stream);
fclose($stream);
break;
}
}