summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/libraries/Zip.php25
-rw-r--r--user_guide_src/source/changelog.rst1
2 files changed, 15 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);
diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst
index 2ad8eff0f..cf15e0fe2 100644
--- a/user_guide_src/source/changelog.rst
+++ b/user_guide_src/source/changelog.rst
@@ -367,6 +367,7 @@ Release Date: Not Released
- :doc:`User Agent Library <libraries/user_agent>` will now check if robots are pretending to be mobile clients (helps with e.g. Google indexing mobile website versions).
- Added support for setting :doc:`Table <libraries/table>` class defaults in a config file.
+ - :doc:`Zip Library <libraries/zip>` method ``read_file()`` can now also alter the original file path/name while adding files to an archive.
- Core