noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_zip_extended.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief extends the Zip object
24  */
25 
26 class Zip_Extended extends ZipArchive
27 {
28  /**
29  * Function to recursively add a directory,
30  * sub-directories and files to a zip archive
31  *@note
32  * ODS format expect unix / instead of DIRECTORY_SEPARATOR
33  * otherwise, new file can not be read by OpenOffice
34  * see PHP Bug #48763 ZipArchive produces corrupt OpenOffice.org files
35  */
36  function add_recurse_folder($dir,$zipdir='')
37  {
38  if (is_dir($dir))
39  {
40  if ($dh = opendir($dir))
41  {
42  // Loop through all the files
43  $filenct = 0;
44  while (($file = readdir($dh)) !== false)
45  {
46  //If it's a folder, run the function again!
47  if(!is_file($dir . $file))
48  {
49  // Skip parent and root directories
50  if( ($file !== ".") && ($file !== ".."))
51  {
52  $this->add_recurse_folder($dir . $file . '/', $zipdir . $file . '/');
53  }
54  }
55  else
56  {
57  // Add the files
58  $this->addFile($dir . $file, $zipdir . $file);
59  $filenct +=1;
60  }
61  }
62  //Add the directory when folder was empty
63  if( (!empty($zipdir)) && ($filenct==0))
64  {
65  // remove directory separator before addEmptyDir
66  // otherwhisen create double folder in zip
67  $this->addEmptyDir(substr($zipdir, 0, -1));
68  }
69  }
70  }
71  }
72 
73 }
$dir
Definition: file-dir.php:3
add_recurse_folder($dir, $zipdir='')
Function to recursively add a directory, sub-directories and files to a zip archive.