PHP code example of markocupic / zip-bundle
1. Go to this page and download the library: Download markocupic/zip-bundle 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/ */
markocupic / zip-bundle example snippets
// Add dir recursive with unlimited depth, add dot files and folders too and store it to a given zip-file
$zip = (new \Markocupic\ZipBundle\Zip\Zip())
->ignoreDotFiles(false)
->stripSourcePath('path/to/source/dir')
->addDirRecursive('path/to/source/dir')
->run('path/to/destination/dir/myZip.zip');
// Add dir recursive depth: 1, collect only files and ignore empty folders
$zip = (new \Markocupic\ZipBundle\Zip\Zip())
->stripSourcePath('path/to/source/dir')
->addDirRecursive('path/to/source/dir', 1, true)
->run('path/to/destination/dir/myZip.zip');
// Add a file
$zip = (new \Markocupic\ZipBundle\Zip\Zip())
->stripSourcePath('path/to/source/dir')
->addFile('path/to/source/dir/myFile.txt')
->run('path/to/destination/dir/myZip.zip');
// Add files from a directory
$zip = (new \Markocupic\ZipBundle\Zip\Zip())
->stripSourcePath('path/to/source/dir')
->addDir('path/to/source/dir')
->run('path/to/destination/dir/myZip.zip');
// Add files from a directory
$zip = (new \Markocupic\ZipBundle\Zip\Zip())
->stripSourcePath('path')
->addDir('path/to/source/dir')
->addDir('path/toAnotherDir/source/dir')
->run('path/to/destination/dir/myZip.zip');