summaryrefslogtreecommitdiffstats
path: root/system
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2014-01-07 14:23:10 +0100
committerAndrey Andreev <narf@devilix.net>2014-01-07 14:23:10 +0100
commita20ec975e653f501cca8e1cf57a9ea244417990f (patch)
tree15c31bb26e834a499d01c84c6fcf1529dfcf558f /system
parent3b2803ef6ddd72772bf5bcb130ace207bc10d60e (diff)
Add ability for changing the original file path/name in CI_Zip::read_file()
Supersedes PR #884
Diffstat (limited to 'system')
-rw-r--r--system/libraries/Zip.php25
1 files changed, 14 insertions, 11 deletions
diff --git a/system/libraries/Zip.php b/system/libraries/Zip.php
index 2ce457844..229b1ecbc 100644
--- a/system/libraries/Zip.php
+++ b/system/libraries/Zip.php
@@ -279,22 +279,25 @@ class CI_Zip {
* Read the contents of a file and add it to the zip
*
* @param string $path
- * @param bool $preserve_filepath
+ * @param bool $archive_filepath
* @return bool
*/
- public function read_file($path, $preserve_filepath = FALSE)
+ public function read_file($path, $archive_filepath = FALSE)
{
- if ( ! file_exists($path))
- {
- return FALSE;
- }
-
- if (FALSE !== ($data = file_get_contents($path)))
+ if (file_exists($path) && FALSE !== ($data = file_get_contents($path)))
{
- $name = str_replace('\\', '/', $path);
- if ($preserve_filepath === FALSE)
+ if (is_string($archive_filepath))
{
- $name = preg_replace('|.*/(.+)|', '\\1', $name);
+ $name = str_replace('\\', '/', $archive_filepath);
+ }
+ else
+ {
+ $name = str_replace('\\', '/', $path);
+
+ if ($preserve_filepath === FALSE)
+ {
+ $name = preg_replace('|.*/(.+)|', '\\1', $name);
+ }
}
$this->add_data($name, $data);