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

[eluser]llbbl[/eluser]
this is used for page compression or to compress files on the server ?
#3

[eluser]eedfwChris[/eluser]
This is primarily to compress a file on the server but you could (though I have never tried) possibly get the contents of a website. You would use a different method in the zip class to zip a variable.
#4

[eluser]stepwl[/eluser]
That is exactly what i need. Thank you webPragmatist!!!




Theme © iAndrew 2016 - Forum software by © MyBB