/var/www/hkosl.com/citysuper/uploader/lib/class_zipFolder.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

/** This file is part of KCFinder project. The class are taken from
  * http://www.php.net/manual/en/function.ziparchive-addemptydir.php
  *
  *      @desc Directory to ZIP file archivator
  *   @package KCFinder
  *   @version 3.12
  *    @author Pavel Tzonkov <sunhater@sunhater.com>
  * @copyright 2010-2014 KCFinder Project
  *   @license http://opensource.org/licenses/GPL-3.0 GPLv3
  *   @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  *      @link http://kcfinder.sunhater.com
  */

namespace kcfinder;

class 
zipFolder {
    protected 
$zip;
    protected 
$root;
    protected 
$ignored;

    function 
__construct($file$folder$ignored=null) {
        
$this->zip = new \ZipArchive();

        
$this->ignored is_array($ignored)
            ? 
$ignored
            
: ($ignored ? array($ignored) : array());

        if (
$this->zip->open($file, \ZipArchive::CREATE) !== TRUE)
            throw new \
Exception("cannot open <$file>\n");

        
$folder rtrim($folder'/');

        if (
strstr($folder'/')) {
            
$this->root substr($folder0strrpos($folder'/') + 1);
            
$folder substr($folderstrrpos($folder'/') + 1);
        }

        
$this->zip($folder);
        
$this->zip->close();
    }

    function 
zip($folder$parent=null) {
        
$full_path "{$this->root}$parent$folder";
        
$zip_path "$parent$folder";
        
$this->zip->addEmptyDir($zip_path);
        
$dir = new \DirectoryIterator($full_path);
        foreach (
$dir as $file)
            if (!
$file->isDot()) {
                
$filename $file->getFilename();
                if (!
in_array($filename$this->ignored)) {
                    if (
$file->isDir())
                        
$this->zip($filename"$zip_path/");
                    else
                        
$this->zip->addFile("$full_path/$filename""$zip_path/$filename");
                }
            }
    }
}

?>