CI_Zip::read_dir PHP Method

read_dir() public method

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.
public read_dir ( string $path, boolean $preserve_filepath = TRUE, string $root_path = NULL ) : boolean
$path string path to source directory
$preserve_filepath boolean
$root_path string
return boolean
    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;
    }