CI_Zip::read_dir()

read_dir($path[, $preserve_filepath = TRUE[, $root_path = NULL]])

Parameters:
  • $path (string) – Path to directory
  • $preserve_filepath (bool) – Whether to maintain the original path
  • $root_path (string) – Part of the path to exclude from the archive directory
Returns:

TRUE on success, FALSE on failure

Return type:

bool

Permits you to compress a directory (and its contents) that already exists somewhere on your server. Supply a path to the directory and the zip class will recursively read and recreate it as a Zip archive. All files contained within the supplied path will be encoded, as will any sub-directories contained within it. Example:

$path = '/path/to/your/directory/';

$this->zip->read_dir($path);

// Download the file to your desktop. Name it "my_backup.zip"
$this->zip->download('my_backup.zip');

By default the Zip archive will place all directories listed in the first parameter inside the zip. If you want the tree preceding the target directory to be ignored, you can pass FALSE (boolean) in the second parameter. Example:

$path = '/path/to/your/directory/';

$this->zip->read_dir($path, FALSE);

This will create a ZIP with a directory named “directory” inside, then all sub-directories stored correctly inside that, but will not include the /path/to/your part of the path.

doc_CodeIgniter
2016-10-15 16:32:09
Comments
Leave a Comment

Please login to continue.