public static function folderToZip($folder, &$zipFile, $exclusiveLength, $exclude = array('.git'), $prefix = '') {
	if (!file_exists($folder)) return;
    $handle = opendir($folder);
    while (false !== $f = readdir($handle)) {
      if ($f != '.' && $f != '..') {
		  
		if (in_array($f, $exclude)) continue;
		  
        $filePath = "$folder/$f";
        // Remove prefix from file path before add to zip.
        $localPath = $prefix.substr($filePath, $exclusiveLength);
        if (is_file($filePath)) {
          $zipFile->addFile($filePath, $localPath);
        } elseif (is_dir($filePath)) {
          // Add sub-directory.
          $zipFile->addEmptyDir($localPath);
          self::folderToZip($filePath, $zipFile, $exclusiveLength, $exclude, $prefix);
        }
      }
    }
    closedir($handle);
  }
public static function folderToZip($folder, &$zipFile, $exclusiveLength, $exclude = array('.git'), $prefix = '') {
	if (!file_exists($folder)) return;
    $handle = opendir($folder);
    while (false !== $f = readdir($handle)) {
      if ($f != '.' && $f != '..') {
		  
		if (in_array($f, $exclude)) continue;
		  
        $filePath = "$folder/$f";
        // Remove prefix from file path before add to zip.
        $localPath = $prefix.substr($filePath, $exclusiveLength);
        if (is_file($filePath)) {
          $zipFile->addFile($filePath, $localPath);
        } elseif (is_dir($filePath)) {
          // Add sub-directory.
          $zipFile->addEmptyDir($localPath);
          self::folderToZip($filePath, $zipFile, $exclusiveLength, $exclude, $prefix);
        }
      }
    }
    closedir($handle);
  }
public static function folderToZip ( $ folder , & $ zipFile , $ exclusiveLength , $ exclude = array ( '.git' ) , $ prefix = '' ) { if ( ! file_exists ( $ folder ) ) return ; $ handle = opendir ( $ folder ) ; while ( false !== $ f = readdir ( $ handle ) ) { if ( $ f != '.' && $ f != '..' ) { if ( in_array ( $ f , $ exclude ) ) continue ; $ filePath = "$folder/$f" ; // Remove prefix from file path before add to zip. $ localPath = $ prefix . substr ( $ filePath , $ exclusiveLength ) ; if ( is_file ( $ filePath ) ) { $ zipFile -> addFile ( $ filePath , $ localPath ) ; } elseif ( is_dir ( $ filePath ) ) { // Add sub-directory. $ zipFile -> addEmptyDir ( $ localPath ) ; self :: folderToZip ( $ filePath , $ zipFile , $ exclusiveLength , $ exclude , $ prefix ) ; } } } closedir ( $ handle ) ; }
Add files and sub-directories in a folder to zip file.

@param string $folder
@param \ZipArchive $zipFile
@param int $exclusiveLength Number of text to be exclusived from the file path.
Add files and sub - directories in a folder to zip file .