PHP code example of verseles / sevenzip

1. Go to this page and download the library: Download verseles/sevenzip 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/ */

    

verseles / sevenzip example snippets


$sevenZip = new SevenZip();
$sevenZip->format('7z')
         ->source('/path/to/source/file/or/directory')
         ->target('/path/to/archive.7z')
         ->compress();

$sevenZip = new SevenZip();
$sevenZip->source('/path/to/archive.7z')
         ->target('/path/to/extract/directory')
         ->extract();

$sevenZip = new SevenZip();
$sevenZip->source('/path/to/source/file/or/directory')
         ->target('/path/to/encrypted_archive.7z')
         ->encrypt('your_password')
         ->compress();

$sevenZip->notEncryptNames();

$sevenZip->setZipEncryptionMethod('AES256');

$sevenZip = new SevenZip();
$sevenZip->source('/path/to/encrypted_archive.7z')
         ->target('/path/to/extract/directory')
         ->decrypt('your_password')
         ->extract();

$sevenZip->

$sevenZip->exclude(['*.md', '*.pdf'])->compress();

$sevenZip = new SevenZip();

// Check if a single format is supported
if ($sevenZip->checkSupport('zip')) {
    echo "ZIP format is supported.";
} else {
    echo "ZIP format is not supported.";
}

// Check if multiple formats are supported
if ($sevenZip->checkSupport(['zip', 'tar', '7z'])) {
    echo "ZIP, TAR, and 7Z formats are supported.";
} else {
    echo "One or more formats are not supported.";
}

$sevenZip->addFlag('mfb', 64);

$sevenZip = new SevenZip();

// Check if a single format is supported
$isZipSupported = $sevenZip->checkSupport('zip');

// Check if multiple formats are supported
$areFormatsSupported = $sevenZip->checkSupport(['zip', 'tar', '7z']);

$sevenZip->compress();

$sevenZip->extract();

$sevenZip->deleteSourceAfterExtract();

$info = $sevenZip->fileInfo();

$list = $sevenZip->fileList();

$formattedFlags = $sevenZip->flagrize(['m0' => 'lzma2', 'mx' => 9]);
// Output: ['-m0=lzma2', '-mx=9']

$sevenZip->format('7z');

$sevenZip = new SevenZip();
$supportedFormats = $sevenZip->getSupportedFormatExtensions();

if (in_array('zip', $supportedFormats)) {
echo "ZIP format is supported.";
} else {
echo "ZIP format is not supported.";
}

$sevenZip->exclude(['*.md', '*.pdf']);

$sevenZip->

$sevenZip->mmem(32); // Set memory limit to 32 MB

$sevenZip->mmt('on'); // Use all available CPU threads
$sevenZip->mmt(4); // Use 4 CPU threads

$sevenZip->mpass(15); // Use 15 compression passes

$sevenZip->mx(9); // Maximum compression

$sevenZip->progress(function ($progress) {
    echo "Progress: {$progress}%\n";
});

$sevenZip->setCustomFlags(['mx' => 9, 'mfb' => 64]);

$sevenZip->setFormat('zip');

$sevenZip->setSourcePath('/path/to/source/file/or/directory');

$sevenZip->setTargetPath('/path/to/archive.7z');

$sevenZip->tarBefore();

$sevenZip->forceTarBefore(true);

$sevenZip->keepFileInfoOnTar(false);