v9.0.0 zip fonctionne reste le téléchargement

This commit is contained in:
fredtempez 2018-12-26 20:20:43 +01:00
parent 6ec892e7a4
commit f620b45c60

View File

@ -525,18 +525,27 @@ class theme extends common {
'state' => true 'state' => true
]); ]);
} }
echo 'site/file/source'.$zipFilename;
echo "<p>";
echo $folderTemp;
// Création du ZIP // Création du ZIP
$this->create_zip($folderTemp, 'site/file/source'.$zipFilename); $zip = new ZipArchive();
die(); $zip->open('site/tmp/' . $zipFilename, ZipArchive::CREATE | ZipArchive::OVERWRITE );
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($folderTemp), RecursiveIteratorIterator::LEAVES_ONLY);
foreach ($files as $name => $file)
{
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($folderTemp)+3);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
// Téléchargement du ZIP // Téléchargement du ZIP
header('Content-Transfer-Encoding: binary'); header('Content-Transfer-Encoding: binary');
header('Content-Disposition: attachment; filename="' . $fileName . '"'); header('Content-Disposition: attachment; filename="' . $zipFileName . '"');
header('Content-Length: ' . filesize('site/tmp/' . $fileName)); header('Content-Length: ' . filesize('site/tmp/' . $zipFileName));
readfile('site/tmp/' . $fileName); readfile('site/tmp/' . $zipFileName);
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'display' => self::DISPLAY_RAW 'display' => self::DISPLAY_RAW
@ -551,29 +560,5 @@ class theme extends common {
// compress all files in the source directory to destination directory
public function create_zip($files = array(), $dest = '', $overwrite = false) {
if (file_exists($dest) && !$overwrite) {
return false;
}
if (($files)) {
$zip = new ZipArchive();
if ($zip->open($dest, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
foreach ($files as $file) {
$zip->addFile($file, $file);
}
$zip->close();
return file_exists($dest);
} else {
return false;
}
}
public function addzip($source, $destination) {
$files_to_zip = glob($source . '/*');
create_zip($files_to_zip, $destination);
}
} }