Welcome Guest, Not a member yet? Register   Sign In
CI Zip Library
#3

[eluser]louis w[/eluser]
After testing this out, I didn't like how the data inside the folder I was trying to add still needed to be inside a directory in the archive. I checked out the CI read_dir call, a couple small changes you can call read_dir to create an archive containing all the files without any directories. Even works with nested folders.

Code:
class MY_Zip extends CI_Zip {

    function read_dir($path, $base=null) {    
    
        if (is_null($base)) $base = $path;

        if ($fp = @opendir($path)) {

            while (FALSE !== ($file = readdir($fp))) {

                if (@is_dir($path.$file) && substr($file, 0, 1) != '.') {    
                    $this->read_dir($path.$file."/", $base);
                } else if (substr($file, 0, 1) != ".") {
                    if (FALSE !== ($data = file_get_contents($path.$file))) {                        
                        $file_name = ltrim($path.$file, $base);
                        $this->add_data($file_name, $data);
                    }
                }
            }

            return TRUE;

        }
    }
        
}


Messages In This Thread
CI Zip Library - by El Forum - 04-17-2009, 11:41 PM
CI Zip Library - by El Forum - 04-24-2009, 08:46 AM
CI Zip Library - by El Forum - 04-24-2009, 09:26 AM
CI Zip Library - by El Forum - 04-24-2009, 09:46 AM
CI Zip Library - by El Forum - 02-15-2011, 02:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB