noalyss Version-9
Public Member Functions
Zip_Extended Class Reference

extends the Zip object More...

+ Inheritance diagram for Zip_Extended:
+ Collaboration diagram for Zip_Extended:

Public Member Functions

 add_file_pattern ( $p_folder, $p_pattern)
 add file to the current file from a folder matching the pattern $p_pattern More...
 
 add_recurse_folder ($dir, $zipdir='')
 Function to recursively add a directory, sub-directories and files to a zip archive. More...
 

Detailed Description

extends the Zip object

Definition at line 31 of file zip_extended.class.php.

Member Function Documentation

◆ add_file_pattern()

Zip_Extended::add_file_pattern (   $p_folder,
  $p_pattern 
)

add file to the current file from a folder matching the pattern $p_pattern

Parameters
$p_folderstring folder where are the file to add
$p_patternstring pattern syntax preg_match
Returns
int number of files added
Exceptions
throwan exception err message is ERR-EZ95 if file cannot be added

Definition at line 85 of file zip_extended.class.php.

85 :int
86 {
87 if (!is_dir($p_folder)) {
88 throw new \Exception("ERR-ZE87");
89
90 }
91 $dir=opendir($p_folder);
92 if( $dir==false) throw new \Exception("ERR-ZE90");
93 $added=0;
94 while( ($entry=readdir($dir)) != false) {
95 if ( preg_match($p_pattern, $entry)) {
96 if ( ! $this->addFile($p_folder . "/" . $entry,$entry) )
97 throw new \Exception("ERR-EZ95 : cannot add $p_folder/$entry");
98 $added++;
99 }
100 }
101 return $added;
102 }
$dir
Definition: file-dir.php:3

References $dir.

◆ add_recurse_folder()

Zip_Extended::add_recurse_folder (   $dir,
  $zipdir = '' 
)

Function to recursively add a directory, sub-directories and files to a zip archive.

Note
ODS format expect unix / instead of DIRECTORY_SEPARATOR otherwise, new file can not be read by OpenOffice see PHP Bug #48763 ZipArchive produces corrupt OpenOffice.org files

Definition at line 41 of file zip_extended.class.php.

42 {
43 if (is_dir($dir))
44 {
45 if ($dh = opendir($dir))
46 {
47 // Loop through all the files
48 $filenct = 0;
49 while (($file = readdir($dh)) !== false)
50 {
51 //If it's a folder, run the function again!
52 if(!is_file($dir . $file))
53 {
54 // Skip parent and root directories
55 if( ($file !== ".") && ($file !== ".."))
56 {
57 $this->add_recurse_folder($dir . $file . '/', $zipdir . $file . '/');
58 }
59 }
60 else
61 {
62 // Add the files
63 $this->addFile($dir . $file, $zipdir . $file);
64 $filenct +=1;
65 }
66 }
67 //Add the directory when folder was empty
68 if( (!empty($zipdir)) && ($filenct==0))
69 {
70 // remove directory separator before addEmptyDir
71 // otherwhisen create double folder in zip
72 $this->addEmptyDir(substr($zipdir, 0, -1));
73 }
74 }
75 }
76 }
add_recurse_folder($dir, $zipdir='')
Function to recursively add a directory, sub-directories and files to a zip archive.

References $dir, $file, and add_recurse_folder().

Referenced by add_recurse_folder().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: