removed pclzip

This commit is contained in:
Ryan
2025-03-10 04:51:15 -04:00
committed by GitHub
parent 186b02da79
commit e1b15a5295
3 changed files with 24 additions and 5443 deletions

View File

@@ -1,8 +1,6 @@
<?php <?php
// downloadZip.php session_start();
require_once 'config.php'; require_once 'config.php';
require_once 'lib/pclzip.lib.php';
// Check if the user is authenticated. // Check if the user is authenticated.
if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) { if (!isset($_SESSION['authenticated']) || $_SESSION['authenticated'] !== true) {
@@ -54,7 +52,6 @@ if ($baseDir === false) {
$folderPath = $baseDir . DIRECTORY_SEPARATOR . $relativePath; $folderPath = $baseDir . DIRECTORY_SEPARATOR . $relativePath;
$folderPathReal = realpath($folderPath); $folderPathReal = realpath($folderPath);
if ($folderPathReal === false || strpos($folderPathReal, $baseDir) !== 0) { if ($folderPathReal === false || strpos($folderPathReal, $baseDir) !== 0) {
http_response_code(404); http_response_code(404);
header('Content-Type: application/json'); header('Content-Type: application/json');
@@ -95,19 +92,24 @@ if (empty($filesToZip)) {
} }
// Create a temporary file for the ZIP archive. // Create a temporary file for the ZIP archive.
$tempZip = tempnam(sys_get_temp_dir(), 'zip') . '.zip'; $tempZip = tempnam(sys_get_temp_dir(), 'zip');
unlink($tempZip); // Remove the temporary file so ZipArchive can create a new one.
$tempZip .= '.zip';
// Create the archive using PclZip. $zip = new ZipArchive();
$archive = new PclZip($tempZip); if ($zip->open($tempZip, ZipArchive::CREATE) !== TRUE) {
$v_list = $archive->create($filesToZip, PCLZIP_OPT_REMOVE_PATH, $folderPathReal);
if ($v_list === 0) {
http_response_code(500); http_response_code(500);
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode(["error" => "Failed to create zip archive."]); echo json_encode(["error" => "Could not create zip archive."]);
exit; exit;
} }
// Add each file to the archive using its base name.
foreach ($filesToZip as $filePath) {
$zip->addFile($filePath, basename($filePath));
}
$zip->close();
// Serve the ZIP file. // Serve the ZIP file.
header('Content-Type: application/zip'); header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="files.zip"'); header('Content-Disposition: attachment; filename="files.zip"');

File diff suppressed because it is too large Load Diff