Welcome Guest, Not a member yet? Register   Sign In
Zip class: don't store rootfolder in archive but DO store subfolders
#3

[eluser]ocergyNohtna[/eluser]
wow, this thread is from 08.... does anyone know how to remove such a structure? i think we all want the files in the deepest folder to be added at the root of the zip archive. is there anyway to do this without hacking the zip class directly?

heheh, so it's not exactly hacking the zip class... hell it's only one line. i guess i'll rewrite in a config option for the feature.

so actually it's as easy as this:

Code:
function read_dir($path, $folders = FALSE)
    {    
        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)))
                    {    
                        if($folders === TRUE) {
                            $this->add_data(str_replace("\\", "/", $path).$file, $data);
                        } else {
                            $this->add_data($file, $data);
                        }
                    }
                }
            }
            return TRUE;
        }
    }

i just added a new param to pass to read_dir if needed. depending on your typical usage you may would flip it the other way to always put the subfolders, but that's just me. hope this helps someone. Tongue


Messages In This Thread
Zip class: don't store rootfolder in archive but DO store subfolders - by El Forum - 06-12-2010, 01:40 PM



Theme © iAndrew 2016 - Forum software by © MyBB