Hi to all
I am trying to compress a few dir's each having sub-dir's and so on. I have found a script that works for the most part but has an issue with larger dir's. The script is as follows;
$zipfile = 'C:\test\bk_'.date('d_m_Y_H_i_s');
$folders=array('C:\1','C:\2','C:\3','C:\4');
$filenames = array();
function browse($dir) {
global $filenames;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && is_file($dir.'/'.$file)) {
$filenames[] = $dir.'/'.$file;
}
else if ($file != "." && $file != ".." && is_dir($dir.'/'.$file)) {
browse($dir.'/'.$file);
}
}
closedir($handle);
}
return $filenames;
}
foreach($folders as $key =>$directory){
browse($directory);
$zip = new ZipArchive();
if ($zip->open($zipfile.'_'.$key.'.zip', ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open zipfile");
}
foreach ($filenames as $filename) {
$zip->addFile($filename,$filename);
}
$filenames = array();
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
}
The output is;
numfiles: 335
status:0
numfiles: 155
status:0
numfiles: 509
status:11
numfiles: 509
status:11
The files are structured;
1 13.7 mb with 335 files
2 16.6 mb with 155 files
3 53.7 mb with 2187 files
4 55.5 mb with 4611 files
So dir 3 and 4 are not written.
I would welcome any suggestions as to achieving this goal either with this script or something akin.
Many thanks