summaryrefslogtreecommitdiffstats
path: root/system/libraries
diff options
context:
space:
mode:
authorPhil Sturgeon <email@philsturgeon.co.uk>2010-05-11 12:41:59 +0200
committerPhil Sturgeon <email@philsturgeon.co.uk>2010-05-11 12:41:59 +0200
commit26872de184e4aa2ae92bae645782089e9656115d (patch)
treef00477488791602a0f582bb8c51434e9a933087e /system/libraries
parente602683aa6362e2efeb03408cea749cfeaaeef4f (diff)
Added an option to remove the preceding trail of empty folders when creating a Zip archive.
Diffstat (limited to 'system/libraries')
-rw-r--r--system/libraries/Zip.php49
1 files changed, 35 insertions, 14 deletions
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 2c4bd255d..3ba3ddc83 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -270,27 +270,48 @@ class CI_Zip {
* @access public
* @param string path to source
* @return bool
- */
- function read_dir($path)
- {
- if ($fp = @opendir($path))
+ */
+ function read_dir($path, $preserve_filepath = TRUE, $root_path = NULL)
+ {
+ 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 = dirname($path).'/';
+ }
+
+ while (FALSE !== ($file = readdir($fp)))
{
- while (FALSE !== ($file = readdir($fp)))
+ if(substr($file, 0, 1) == '.')
{
- if (@is_dir($path.$file) && substr($file, 0, 1) != '.')
- {
- $this->read_dir($path.$file."/");
- }
- elseif (substr($file, 0, 1) != ".")
+ continue;
+ }
+
+ if (@is_dir($path.$file))
+ {
+ $this->read_dir($path.$file."/", $preserve_filepath, $root_path);
+ }
+
+ else
+ {
+ if (FALSE !== ($data = file_get_contents($path.$file)))
{
- if (FALSE !== ($data = file_get_contents($path.$file)))
- {
- $this->add_data(str_replace("\\", "/", $path).$file, $data);
+ $name = str_replace("\\", "/", $path);
+
+ if ($preserve_filepath === FALSE)
+ {
+ $name = str_replace($root_path, '', $name);
}
+
+ $this->add_data($name.$file, $data);
}
}
- return TRUE;
}
+ return TRUE;
}
// --------------------------------------------------------------------