Welcome Guest, Not a member yet? Register   Sign In
Zip Encoder (read_file extension to allow file name)
#1

[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 Smile.

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");


Messages In This Thread
Zip Encoder (read_file extension to allow file name) - by El Forum - 11-05-2007, 10:20 PM
Zip Encoder (read_file extension to allow file name) - by El Forum - 11-07-2007, 04:06 PM
Zip Encoder (read_file extension to allow file name) - by El Forum - 11-07-2007, 06:07 PM
Zip Encoder (read_file extension to allow file name) - by El Forum - 02-27-2008, 12:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB