PHP code example of codebites / cli-7zip

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

    

codebites / cli-7zip example snippets




use Codebites\Cli7zip\Cli7zip;

// Init
$cli7zip = new Cli7zip();

// Init with custom paths
$cli7zip = new Cli7zip('7zz', ['/path/to/my/binaries_folder']);

// Extract archive without folder creation
$success = $cli7zip->extractArchive('/my/archive.7z', '/my/existing/target/folder');

// Extract archive with folder creation
$success = $cli7zip->extractArchive('/my/archive.7z', '/my/non-existing/target/folder', true);

// Compress directory as 7z
$success = $cli7zip->compressDir('/my/folder/to/compress', '/my/archive.7z', '7z');

// Compress directory as Zip
$archivePath = $cli7zip->compressDir('/my/folder/to/compress', '/my/archive.zip', 'zip');

// Add files to existing archive
$success = $cli7zip->addFilesToArchive('/my/archive.7z', '/my/first/file.txt', '/my/seconde/file2.txt');

// Add string as file to existing archive
$success = $cli7zip->addStringToArchive('/my/archive.7z', 'Hello, World!', 'filename.txt');