Zip class: don't store rootfolder in archive but DO store subfolders

#1
[eluser]codex[/eluser]
When using the Zip encoding class you have to point to a directory that holds the files to be archived. But when you zip the files the root folder is zipped with it also, which I don't want.

I have this piece of code, provided by forum member Tassoman (http://ellislab.com/forums/viewthread/46681/). It pretty much does what I need, but it also strips the subfolders and are therefore not included. I must admit that I don't fully understand what's happening in the code and how/if I can fix it. Anyone got a clue?

Code:
class MY_Zip extends CI_Zip {

    function MY_Zip() {
        parent::CI_Zip();
    }

    function read_dir($path)
    {
        if ($fp = @opendir($path))
        {
            while (FALSE !== ($file = readdir($fp)))
            {
                if (@is_dir($path.$file) && substr($file, 0, 1) != '.')
                {
                    $this->read_dir($path.$file."/");
                }
                elseif (substr($file, 0, 1) != ".")
                {
                    if (FALSE !== ($data = file_get_contents($path.$file)))
                    {
                        $this->add_data($file, $data);
                    }
                }
            }
            return TRUE;
        }
    }
}


Messages In This Thread
Zip class: don't store rootfolder in archive but DO store subfolders - by El Forum - 02-01-2008, 11:44 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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