• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Zip Encoder (read_file extension to allow file name)

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):
<?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;

    // ------------------------------------------------------------------------


// 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 is used for page compression or to compress files on the server ?

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.

That is exactly what i need. Thank you webPragmatist!!!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.