[eluser]eedfwChris[/eluser]
Not much of an addition, more of a "hey why doesn't this allow this?"
With this function you can still name the file in the zip even if you are getting it from a file source. Hopefully this works for someone because I stopped using it shortly after I made it. All I did was change one line

.
Code (APPPATH/libraries/MY_Zip.php):Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class MY_Zip extends CI_Zip
{
/**
* Read the contents of a file and add it to the zip (while still allowing a filename)
*
* @author Rick Ellis
* @extender Athfar (Chris LeBlanc)
*
* @access public
* @param $path
* @param $name
* @return bool
*/
function read_file($path, $name = FALSE, $preserve_filepath = FALSE)
{
if ( ! file_exists($path))
{
return FALSE;
}
if (FALSE !== ($data = file_get_contents($path)))
{
$name = ($name !== FALSE) ? $name : str_replace("\\", "/", $path);
if ($preserve_filepath === FALSE)
{
$name = preg_replace("|.*/(.+)|", "\\1", $name);
}
$this->add_data($name, $data);
return TRUE;
}
return FALSE;
}
// ------------------------------------------------------------------------
}
Usage:Code:
$this->load->library('zip');
// Generic user we will use later
$user = "Bob";
// Here's our real file named doohicky.exe
$file = APPPATH."/files/doohicky.exe";
// Waaaah I want Bob to seem special even though he really is getting the same .exe as everyone else!
$this->zip->read_file($file, "{$user}_doohicky.exe");
$this->zip->download("zip");