Welcome Guest, Not a member yet? Register   Sign In
Performance issue of Zip Class
#11

[eluser]ocergyNohtna[/eluser]
where does this go/how is it used?? sorry, still a bit new. I found another post and made one change in the Zip.php Library
Code:
//$this->add_data(str_replace("\\", "/", $path).$file, $data);
$this->add_data($file, $data);

which results in all files put into the archive without any folders...but i think what you have is what i want...just can't figure out how to implement.
#12

[eluser]stanleyxu[/eluser]
[quote author="ocergyNohtna" date="1202676887"]where does this go/how is it used?? sorry, still a bit new. I found another post and made one change in the Zip.php Library
Code:
//$this->add_data(str_replace("\\", "/", $path).$file, $data);
$this->add_data($file, $data);

which results in all files put into the archive without any folders...but i think what you have is what i want...just can't figure out how to implement.[/quote]

Code:
$this->load->library('zip'); // zip object (extended)
$this->zip->add_all_($path_to_dir);
$this->zip->archive($your_zip_file);
To note, that my version will create a zip like it is created by winzip. Test it and you will know how it works.
#13

[eluser]ocergyNohtna[/eluser]
and i put
Code:
/**
     * Add a complete directory snapshot to Zip
     *
     * @access  public
     * @param   string  physical path to the root
     * @param   string  used internally
     * @return  void
     */
    function add_all_($root, $zip_prefix = '')
    {
        $CI =& get_instance();
        $CI->load->helper('directory'); // directory_map

        foreach (directory_map($root, TRUE as $item)
        {
            $filename = $root.'/'.$item;
            
            if (is_file($filename))
            {
                $this->add_data(
                    $zip_prefix.$item, file_get_contents($filename));
            }
            else
            {
                $this->add_dir($zip_prefix.$item);
                $this->add_all_(// recursively
                    $filename, $zip_prefix.$item.'/');
            }
        }
    }
in the Zip.php library...

but i get a Parse error: syntax error, unexpected T_AS in Zip.php on line 263 which is referencing the foreach loop

i don't know what i've done now...o_O
#14

[eluser]stanleyxu[/eluser]
[quote author="ocergyNohtna" date="1202677603"]and i put code in the Zip.php library...

but i get a Parse error: syntax error, unexpected T_AS in Zip.php on line 263 which is referencing the foreach loop

i don't know what i've done now...o_O[/quote]

Hey buddy, sorry, i have skipped some steps.

1. Please read this article: http://ellislab.com/codeigniter/user-gui...aries.html
2. Create a MY_Zip.php in application/libraries
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
// copyright infos ...
class MY_Zip extends CI_Zip {

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

    // Copy and paste the code in previous reply
    function add_all_($root, $zip_prefix = '')
    ....
3. My code should work now.
#15

[eluser]ocergyNohtna[/eluser]
made those changes. and that makes sense too. the user guide was straight to the point. i'm enjoying CI more every day. although... i'm still getting a parse error on the foreach loop...
#16

[eluser]ocergyNohtna[/eluser]
wait...i think i fixed it:

changed
Code:
foreach (directory_map($root, TRUE as $item)
to
Code:
foreach (directory_map($root, TRUE) as $item)
but now I get a Fatal error: Class 'CI_Zip' not found in C:\xampp\www\dev\system\application\libraries\MY_Zip.php on line 2
#17

[eluser]stanleyxu[/eluser]
[quote author="ocergyNohtna" date="1202678586"]made those changes. and that makes sense too. the user guide was straight to the point. i'm enjoying CI more every day. although... i'm still getting a parse error on the foreach loop...[/quote]
sorry, it was a type mistake. Enjoy it^^)
#18

[eluser]Esko[/eluser]
Thank you. Your enhanced ZIP and UNZIP libraries made my day.
#19

[eluser]Shrike67[/eluser]
Someone has this library?
Can you post it in the wiki or give me a working link?

Thanks
#20

[eluser]stanleyxu[/eluser]
[quote author="Shrike67" date="1247519503"]Someone has this library?
Can you post it in the wiki or give me a working link?

Thanks[/quote]
I have fixed this file link. Please try again or use the current version. It has been fixed already.




Theme © iAndrew 2016 - Forum software by © MyBB