Skip to content

Commit

Permalink
https://github.com/WWBN/AVideo-Encoder/issues/527
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Feb 23, 2024
1 parent 29a06d3 commit ab7dded
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,26 +661,34 @@ function zipDirectory($destinationFile) {
if (!is_object($zip)) {
$zip = new \ZipArchive;
}
$zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE);

if ($zip->open($zipPath, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
throw new Exception("Cannot open <$zipPath>\n");
}
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);

$countFilesAdded = 0;
foreach ($files as $name => $file) {
$filePath = $file->getRealPath();
// Skip directories (they would be added automatically)
if (!$file->isDir()) {
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);

// Add current file to archive
$zip->addFile($filePath, $relativePath);
if (!$zip->addFile($filePath, $relativePath)) {
error_log("zipDirectory: Cannot add file <$filePath>");
}else{
$countFilesAdded++;
}
}else{
error_log("zipDirectory: Cannot add file it is a Dir <$filePath>");
}
}
error_log("zipDirectory($destinationFile) added {$countFilesAdded} files");

// Zip archive will be created only after closing object
$zip->close();
Expand Down

0 comments on commit ab7dded

Please sign in to comment.