src/IronWorker.php
public static function createZip($base_dir, $files, $destination, $overwrite = false)
    {
        //if the zip file already exists and overwrite is false, return false
        if (file_exists($destination) && !$overwrite) {
            return false;
        }
        if (!empty($base_dir)) {
            $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        }
        //vars
        $valid_files = array();
        //if files were passed in...
        if (is_array($files)) {
            //cycle through each file
            foreach ($files as $file) {
                //make sure the file exists
                if (file_exists($base_dir . $file)) {
                    $valid_files[] = $file;
                }
            }
        }
        if (count($valid_files)) {
            $zip = new \ZipArchive();
            if ($zip->open($destination, $overwrite ? \ZIPARCHIVE::OVERWRITE : \ZIPARCHIVE::CREATE) !== true) {
                return false;
            }
            foreach ($valid_files as $file) {
                $zip->addFile($base_dir . $file, $file);
            }
            $zip->close();
            return file_exists($destination);
        } else {
            return false;
        }
    }
public static function createZip($base_dir, $files, $destination, $overwrite = false)
    {
        //if the zip file already exists and overwrite is false, return false
        if (file_exists($destination) && !$overwrite) {
            return false;
        }
        if (!empty($base_dir)) {
            $base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
        }
        //vars
        $valid_files = array();
        //if files were passed in...
        if (is_array($files)) {
            //cycle through each file
            foreach ($files as $file) {
                //make sure the file exists
                if (file_exists($base_dir . $file)) {
                    $valid_files[] = $file;
                }
            }
        }
        if (count($valid_files)) {
            $zip = new \ZipArchive();
            if ($zip->open($destination, $overwrite ? \ZIPARCHIVE::OVERWRITE : \ZIPARCHIVE::CREATE) !== true) {
                return false;
            }
            foreach ($valid_files as $file) {
                $zip->addFile($base_dir . $file, $file);
            }
            $zip->close();
            return file_exists($destination);
        } else {
            return false;
        }
    }
public static function createZip ( $ base_dir , $ files , $ destination , $ overwrite = false ) { //if the zip file already exists and overwrite is false, return false if ( file_exists ( $ destination ) && ! $ overwrite ) { return false ; } if ( ! empty ( $ base_dir ) ) { $ base_dir = rtrim ( $ base_dir , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR ; } //vars $ valid_files = array ( ) ; //if files were passed in... if ( is_array ( $ files ) ) { //cycle through each file foreach ( $ files as $ file ) { //make sure the file exists if ( file_exists ( $ base_dir . $ file ) ) { $ valid_files [ ] = $ file ; } } } if ( count ( $ valid_files ) ) { $ zip = new \ ZipArchive ( ) ; if ( $ zip -> open ( $ destination , $ overwrite ? \ ZIPARCHIVE :: OVERWRITE : \ ZIPARCHIVE :: CREATE ) !== true ) { return false ; } foreach ( $ valid_files as $ file ) { $ zip -> addFile ( $ base_dir . $ file , $ file ) ; } $ zip -> close ( ) ; return file_exists ( $ destination ) ; } else { return false ; } }
Creates a zip archive from array of file names

Example:
<code>
IronWorker::createZip(dirname(__FILE__), array('HelloWorld.php'), 'worker.zip', true);
</code>

@static
@param string $base_dir Full path to directory which contain files
@param array $files File names, path (both passesed and stored) is relative to $base_dir.
Examples: 'worker.php','lib/file.php'
@param string $destination Zip file name.
@param bool $overwrite Overwite existing file or not.
@return bool
Creates a zip archive from array of file names