PHP code example of virusphp / laravel-zip

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

    

virusphp / laravel-zip example snippets


use Zip;


  $zip = Zip::open('file.zip');

  

  $zip = Zip::create('file.zip');

  

  $is_valid = Zip::check('file.zip');

  

  // extract whole archive
  $zip->extract('/path/to/uncompressed/files');

  // extract a file
  $zip->extract('/path/to/uncompressed/files', 'file');

  // extract multiple files
  $zip->extract('/path/to/uncompressed/files', array('file1','file2'));

  

  // Check if archive has a file
  $zip->has('/path/to/file/in/archive');

  // Check if archive has a file case insensitively
  $zip->has('/path/to/file/in/archive', ZipArchive::FL_NOCASE);

  // Check if archive has a file ignoring directory component
  $zip->has('file', ZipArchive::FL_NODIR);

  // Check if archive has a file case insensitively ignoring directory component
  $zip->has('file', ZipArchive::FL_NOCASE|ZipArchive::FL_NODIR);

  

  $zip->add('/path/to/my/file');

  // declaring path
  $zip->setPath('/path/to/my')->add('file');

  // add directory
  $zip->add('/path/to/my/directory');

  // add directory (only its content)
  $zip->add('/path/to/my/directory', true);

  

  $zip->addFromString('file name with extension', 'content of file');

  $zip->addFromString('filename.txt', $file_content);
  $zip->addFromString('folder/file1.txt', $file_content);
  $zip->addFromString('folder/file2.txt', $file_content);


  

  // using array as parameter
  $zip->add( array('/path/to/my/file1', '/path/to/my/file2');

  // chaining methods
  $zip->add('/path/to/my/file1')->add('/path/to/my/file2');

  // declaring path
  $zip->setPath('/path/to/my')->add('file1')->add('file2');

  

  $zip->delete('file');

  

  // using array as parameter
  $zip->delete( array('file1', 'file2') );

  // chaining methods
  $zip->delete('file1')->delete('file2');

  

  $zip->listFiles();

  

  $zip->close();

  

  // set mode
  $zip->setSkipped('HIDDEN');

  // get mode
  $mode = $zip->getSkipped();

  

  // set password
  $zip->setPassword('slartibartfast');

  // get password
  $password = $zip->getPassword();

  

  // set mask
  $zip->setMask(0644);

  // get mask
  $mask = $zip->getMask();

  

use Virusphp\Zip\ZipManager;
use Zip;

  // init manager
  $manager = new ZipManager();

  // register existing zips
  $manager->addZip( Zip::open('/path/to/my/file1.zip') )
          ->addZip( Zip::open('/path/to/my/file2.zip') );

  // register a new zip
  $manager->addZip( Zip::create('/path/to/my/file3.zip') );

  

  // get a list of registered zips
  $list = $manager->listZips();

  // remove a zip
  $manager->removeZip($ZipObject);

  // get a Zip
  $zip = $manager->getZip(0);

  

  $manager = new ZipManager();

  // register existing zips
  $manager->addZip( Zip::open('/path/to/my/file1.zip') )
          ->addZip( Zip::open('/path/to/my/file2.zip') );

  // register a new zip
  $manager->addZip( Zip::create('/path/to/my/file3.zip') );

  

  // separate content in folders
  $extract = $manager->extract('/path/to/uncompressed/files', true);

  // use a single folder
  $extract = $manager->extract('/path/to/uncompressed/files', false);

  // extract single file
  $extract = $manager->extract('/path/to/uncompressed/files', false, 'file');

  // extract multiple files
  $extract = $manager->extract('/path/to/uncompressed/files', false, array('file1','file2'));

  

  // separate content in folders
  $manager->merge('/path/to/output/file.zip', true);

  // flatten files
  $manager->merge('/path/to/output/file.zip', false);

  

  $manager->close();

  

  // set path
  $zip->setPath('/path/to/files');

  // get path
  $path = $zip->getPath();

  

  // set masks
  $manager->setMask(0644);

  // get masks
  $mask = $manager->getMask();