public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
	{
		$path = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
		if ( ! $fp = @opendir($path))
		{
			return FALSE;
		}

		// Set the original directory root for child dir's to use as relative
		if ($root_path === NULL)
		{
			$root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR;
		}

		while (FALSE !== ($file = readdir($fp)))
		{
			if ($file[0] === '.')
			{
				continue;
			}

			if (is_dir($path.$file))
			{
				$this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path);
			}
			elseif (FALSE !== ($data = file_get_contents($path.$file)))
			{
				$name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
				if ($preserve_filepath === FALSE)
				{
					$name = str_replace($root_path, '', $name);
				}

				$this->add_data($name.$file, $data);
			}
		}

		closedir($fp);
		return TRUE;
	}
public function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
	{
		$path = rtrim($path, '/\\').DIRECTORY_SEPARATOR;
		if ( ! $fp = @opendir($path))
		{
			return FALSE;
		}

		// Set the original directory root for child dir's to use as relative
		if ($root_path === NULL)
		{
			$root_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, dirname($path)).DIRECTORY_SEPARATOR;
		}

		while (FALSE !== ($file = readdir($fp)))
		{
			if ($file[0] === '.')
			{
				continue;
			}

			if (is_dir($path.$file))
			{
				$this->read_dir($path.$file.DIRECTORY_SEPARATOR, $preserve_filepath, $root_path);
			}
			elseif (FALSE !== ($data = file_get_contents($path.$file)))
			{
				$name = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $path);
				if ($preserve_filepath === FALSE)
				{
					$name = str_replace($root_path, '', $name);
				}

				$this->add_data($name.$file, $data);
			}
		}

		closedir($fp);
		return TRUE;
	}
public function read_dir ( $ path , $ preserve_filepath = TRUE , $ root_path = NULL ) { $ path = rtrim ( $ path , '/\\' ) . DIRECTORY_SEPARATOR ; if ( ! $ fp = @ opendir ( $ path ) ) { return FALSE ; } // Set the original directory root for child dir's to use as relative if ( $ root_path === NULL ) { $ root_path = str_replace ( array ( '\\' , '/' ) , DIRECTORY_SEPARATOR , dirname ( $ path ) ) . DIRECTORY_SEPARATOR ; } while ( FALSE !== ( $ file = readdir ( $ fp ) ) ) { if ( $ file [ 0 ] === '.' ) { continue ; } if ( is_dir ( $ path . $ file ) ) { $ this -> read_dir ( $ path . $ file . DIRECTORY_SEPARATOR , $ preserve_filepath , $ root_path ) ; } elseif ( FALSE !== ( $ data = file_get_contents ( $ path . $ file ) ) ) { $ name = str_replace ( array ( '\\' , '/' ) , DIRECTORY_SEPARATOR , $ path ) ; if ( $ preserve_filepath === FALSE ) { $ name = str_replace ( $ root_path , '' , $ name ) ; } $ this -> add_data ( $ name . $ file , $ data ) ; } } closedir ( $ fp ) ; return TRUE ; }
Read a directory and add it to the zip.

This function recursively reads a folder and everything it contains (including
sub-folders) and creates a zip based on it. Whatever directory structure
is in the original file path will be recreated in the zip file.

@param	string	$path	path to source directory
@param	bool	$preserve_filepath
@param	string	$root_path
@return	bool
Read a directory and add it to the zip .