summaryrefslogtreecommitdiffstats
path: root/system/libraries/Zip.php
diff options
context:
space:
mode:
authoradmin <devnull@localhost>2006-10-23 22:02:04 +0200
committeradmin <devnull@localhost>2006-10-23 22:02:04 +0200
commit5725a40301b3aceab1b838e33d003ecaf7ab113e (patch)
tree5cccb0c51c6ab2fa65d9d0daf528a64486dff7dd /system/libraries/Zip.php
parent9f8243b382329609fa24fe84928c8873b380d44c (diff)
Diffstat (limited to 'system/libraries/Zip.php')
-rw-r--r--system/libraries/Zip.php65
1 files changed, 65 insertions, 0 deletions
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 092f9f378..828ef0c25 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -192,6 +192,71 @@ class CI_Zip {
// --------------------------------------------------------------------
/**
+ * Read the contents of a file and add it to the zip
+ *
+ * @access public
+ * @return bool
+ */
+ function read_file($path, $preserve_filepath = FALSE)
+ {
+ if ( ! file_exists($path))
+ {
+ return FALSE;
+ }
+
+ if (FALSE !== ($data = file_get_contents($path)))
+ {
+ $name = str_replace("\\", "/", $path);
+
+ if ($preserve_filepath === FALSE)
+ {
+ $name = preg_replace("|.*/(.+)|", "\\1", $name);
+ }
+
+ $this->add_data($name, $data);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+ // ------------------------------------------------------------------------
+
+ /**
+ * 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.
+ *
+ * @access public
+ * @param string path to source
+ * @return bool
+ */
+ function read_dir($path)
+ {
+ if ($fp = @opendir($path))
+ {
+ while (FALSE !== ($file = readdir($fp)))
+ {
+ if (@is_dir($path.$file) && substr($file, 0, 1) != '.')
+ {
+ $this->read_dir($path.$file."/");
+ }
+ elseif (substr($file, 0, 1) != ".")
+ {
+ if (FALSE !== ($data = file_get_contents($path.$file)))
+ {
+ $this->add_data(str_replace("\\", "/", $path).$file, $data);
+ }
+ }
+ }
+ return TRUE;
+ }
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Get the Zip file
*
* @access public