Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

I added an argument in the read_file function to enable users to rena…

…me the files that they are about to zip. I was thinking of this when I was implementing a sort of gmail download where each file names are encoded and then zipped to be downloaded.
  • Loading branch information...
commit 9d223e50320d02739cc6212e0512cf49f4f1bf26 1 parent 9252d7b
Denis Duvauchelle authored January 08, 2012

Showing 1 changed file with 9 additions and 6 deletions. Show diff stats Hide diff stats

  1. 15  system/libraries/Zip.php
15  system/libraries/Zip.php
@@ -251,7 +251,7 @@ function _add_data($filepath, $data, $file_mtime, $file_mdate)
251 251
 	 * @access	public
252 252
 	 * @return	bool
253 253
 	 */
254  
-	function read_file($path, $preserve_filepath = FALSE)
  254
+	function read_file($path, $preserve_filepath = FALSE, $name = NULL) // Added $name
255 255
 	{
256 256
 		if ( ! file_exists($path))
257 257
 		{
@@ -260,17 +260,20 @@ function read_file($path, $preserve_filepath = FALSE)
260 260
 
261 261
 		if (FALSE !== ($data = file_get_contents($path)))
262 262
 		{
263  
-			$name = str_replace("\\", "/", $path);
  263
+			if($name == NULL)
  264
+			{  // Added a verification to see if it is set, if not set, then it does it's normal thing, if it is set, it uses the defined var.
  265
+				$name = str_replace("\\", "/", $path);
264 266
 
265  
-			if ($preserve_filepath === FALSE)
266  
-			{
267  
-				$name = preg_replace("|.*/(.+)|", "\\1", $name);
  267
+				if ($preserve_filepath === FALSE)
  268
+				{
  269
+					$name = preg_replace("|.*/(.+)|", "\\1", $name);
  270
+				}
268 271
 			}
269 272
 
270 273
 			$this->add_data($name, $data);
271 274
 			return TRUE;
272 275
 		}
273  
-		return FALSE;
  276
+    		return FALSE;
274 277
 	}
275 278
 
276 279
 	// ------------------------------------------------------------------------

0 notes on commit 9d223e5

Please sign in to comment.
Something went wrong with that request. Please try again.