Browse Source

addon export WIP (pages missing)

10504
fredtempez 4 months ago
parent
commit
af72107c79
  1. 32
      core/core.php
  2. 11
      core/module/addon/addon.php

32
core/core.php

@ -1017,6 +1017,38 @@ class common {
return ( rmdir($path) );
}
/**
* Génère une archive d'un dossier et des sous-dossiers
* @param string fileName path et nom de l'archive
* @param string folder path à zipper
* @param array filter dossiers à exclure
*/
public function makeZip ($fileName, $folder, $filter ) {
$zip = new ZipArchive();
$zip->open($fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
//$directory = 'site/';
$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
new RecursiveDirectoryIterator(
$folder,
RecursiveDirectoryIterator::SKIP_DOTS
),
function ($fileInfo, $key, $iterator) use ($filter) {
return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
}
)
);
foreach ($files as $name => $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen(realpath($folder)) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
}
/**
* Mises à jour
*/

11
core/module/addon/addon.php

@ -322,8 +322,8 @@ class addon extends common {
}
}
// création du zip
$fileName = self::TEMP_DIR . '/' . $this->geturl(2) . 'zip';
$this->createZip($fileName,$tmpFolder);
$fileName = $this->getUrl(2) . '.zip';
$this->makeZip ($fileName, $tmpFolder, []);
if (file_exists($fileName)) {
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
@ -333,10 +333,9 @@ class addon extends common {
$this->addOutput([
'display' => self::DISPLAY_RAW
]);
//unlink($filename);
//$this->removeDir($tmpFolder);
// Valeurs en sortie
unlink($fileName);
$this->removeDir($tmpFolder);
exit();
} else {
// Valeurs en sortie
$this->addOutput([

Loading…
Cancel
Save