gavik
Полезный
- Регистрация
- 25 Июл 2010
- Сообщения
- 162
- Реакции
- 15
- Автор темы
- #1
Подскажите, как доработать функцию, чтобы можно было с ее помощью запапковать папку в которой есть файлы, папки с несколькими уровнями вложенности?
PHP:
$destination=tempnam("tmp", "zip");
$zipArchive = new ZipArchive();
$zipArchive->open($destination, ZIPARCHIVE::CREATE); //пытаемся создать архив
function addFolderToZip($dir, $zipArchive){
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
//Add the directory
$zipArchive->addEmptyDir($dir);
// Loop through all the files
while (($file = readdir($dh)) !== false) {
//If it's a folder, run the function again!
if(!is_file($dir . $file)){
// Skip parent and root directories
if( ($file !== ".") && ($file !== "..")){
addFolderToZip($dir . $file . "/", $zipArchive);
}
}else{
// Add the files
$zipArchive->addFile($dir . $file);
}
}
}
}
}