private static function folderToZip($folder, &$zipFile, $parentPath) {
		
		$handle = opendir($folder);
		
		while (false !== $f = readdir($handle)) {
			
			// list of unwanted files
			$excluded = array('.', '..', '.DS_Store', 'thumbs.db');
			
			if (!in_array($f, $excluded)) {
				
				$filePath = $folder . '/' . $f;
				
				// removes prefix from file path before add to zip
				if (0 === strpos($filePath, $parentPath)) {
					$localPath = substr($filePath, strlen($parentPath . '/'));
				} 
				
				if (is_file($filePath)) {
					
					$zipFile->addFile($filePath, $localPath);
					
				} elseif (is_dir($filePath)) {
					
					// adds sub-directory
					$zipFile->addEmptyDir($localPath);
					self::folderToZip($filePath, $zipFile, $parentPath);
				}
				
			}
			
		}
		
		closedir($handle);
		
	}
private static function folderToZip($folder, &$zipFile, $parentPath) {
		
		$handle = opendir($folder);
		
		while (false !== $f = readdir($handle)) {
			
			// list of unwanted files
			$excluded = array('.', '..', '.DS_Store', 'thumbs.db');
			
			if (!in_array($f, $excluded)) {
				
				$filePath = $folder . '/' . $f;
				
				// removes prefix from file path before add to zip
				if (0 === strpos($filePath, $parentPath)) {
					$localPath = substr($filePath, strlen($parentPath . '/'));
				} 
				
				if (is_file($filePath)) {
					
					$zipFile->addFile($filePath, $localPath);
					
				} elseif (is_dir($filePath)) {
					
					// adds sub-directory
					$zipFile->addEmptyDir($localPath);
					self::folderToZip($filePath, $zipFile, $parentPath);
				}
				
			}
			
		}
		
		closedir($handle);
		
	}
private static function folderToZip ( $ folder , & $ zipFile , $ parentPath ) { $ handle = opendir ( $ folder ) ; while ( false !== $ f = readdir ( $ handle ) ) { // list of unwanted files $ excluded = array ( '.' , '..' , '.DS_Store' , 'thumbs.db' ) ; if ( ! in_array ( $ f , $ excluded ) ) { $ filePath = $ folder . '/' . $ f ; // removes prefix from file path before add to zip if ( 0 === strpos ( $ filePath , $ parentPath ) ) { $ localPath = substr ( $ filePath , strlen ( $ parentPath . '/' ) ) ; } if ( is_file ( $ filePath ) ) { $ zipFile -> addFile ( $ filePath , $ localPath ) ; } elseif ( is_dir ( $ filePath ) ) { // adds sub-directory $ zipFile -> addEmptyDir ( $ localPath ) ; self :: folderToZip ( $ filePath , $ zipFile , $ parentPath ) ; } } } closedir ( $ handle ) ; }
Recursively adds all files and all sub-directories to a ZIP file.

@param	string		Folder without trailing slash.
@param	ZipArchive	Reference ZIP file parameter.
@param	string		Parent path that will be excluded from all files path.
Recursively adds all files and all sub - directories to a ZIP file .