fix issue PHP8.1 ZIP::addGlob gives an error , name too long

This commit is contained in:
sparkyx 2024-03-11 22:10:13 +01:00
parent 1484886cfa
commit 4bd53c202b
4 changed files with 40 additions and 6 deletions

View file

@ -75,4 +75,28 @@ class Zip_Extended extends ZipArchive
}
}
/**
* @brief add file to the current file from a folder matching the pattern $p_pattern
* @param $p_folder string folder where are the file to add
* @param $p_pattern string pattern syntax preg_match
* @return int number of files added
*/
function add_file_pattern( $p_folder,$p_pattern):int
{
if (!is_dir($p_folder)) {
throw new \Exception("ERR-ZE87");
}
$dir=opendir($p_folder);
if( $p_folder==false) throw new \Exception("ERR-ZE90");
$added=0;
while( ($entry=readdir($dir)) != false) {
if ( preg_match($p_pattern, $entry)) {
$this->addFile($p_folder . "/" . $entry,$entry);
$added++;
}
}
return $added;
}
}