zip

🔧 __construct

function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

🔧 __construct

function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

🔧 __construct

function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

🔧 __construct

function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

🔧 __construct

function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

🔧 __construct

Constructor
function __construct($prefix = 'export') { $this->zipDir = dirname(__FILE__) . '/../../../../../../data/'; $this->zipName = $prefix . '_' . date('Y-m-d_His') .'.zip'; $this->zipPath = $this->zipDir . $this->zipName; $this->init(); }

âš™ī¸ Parameters


🔧 init

Initialize the ZIP archive
function init() { ob_start(); // Ensure the zip directory exists if (!file_exists($this->zipDir)) { mkdir($this->zipDir, 0755, true); } // Create the ZIP file $this->zip = new ZipArchive(); if ($this->zip->open($this->zipPath, ZipArchive::OVERWRITE) !== TRUE) { if ($this->zip->open($this->zipPath, ZipArchive::CREATE) !== TRUE) { throw new Exception("Cannot create zip file"); } // ... (truncated)

â†Šī¸ Returns

(bool) Success status

âš ī¸ Throws


🔧 addFile

Add a file to the ZIP archive
function addFile($filePath, $filename) { if (!file_exists($filePath)) { return false; } $this->files[] = [$filePath => $filename]; return $this->zip->addFile($filePath, $filename); }

âš™ī¸ Parameters

â†Šī¸ Returns

(bool) Success status

🔧 addCSV

Create a CSV file and add it to the ZIP
function addCSV($csvName, array $headers, array $data) { $csvPath = $this->zipDir . '/' . $csvName; $csvHandle = fopen($csvPath, 'w'); // Write headers fputcsv($csvHandle, $headers); // Write data foreach ($data as $row) { fputcsv($csvHandle, $row); } fclose($csvHandle); // Add CSV to ZIP $this->addFile($csvPath, $csvName); // Mark file for cleanup $this->filesToCleanup[] = $csvPath; // ... (truncated)

âš™ī¸ Parameters

â†Šī¸ Returns

(bool) Success status

🔧 close

Close the ZIP archive
function close() { return $this->zip->close(); }

â†Šī¸ Returns

(bool) Success status

🔧 download

Send the ZIP file to the browser for download
function download() { $this->close(); // Set headers to force download header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="' . $this->zipName . '"'); header('Content-Length: ' . filesize($this->zipPath)); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache'); var_dump(filesize($this->zipPath)); $content = ob_get_contents(); // ... (truncated)

âš ī¸ Throws


🔧 cleanup

Clean up temporary files
function cleanup() { foreach ($this->filesToCleanup as $file) { if (file_exists($file)) { unlink($file); } } }

🔧 getZipPath

Get the full path to the ZIP file
function getZipPath() { return $this->zipPath; }

â†Šī¸ Returns

(string) ZIP file path

🔧 getZipName

Get the ZIP file name
function getZipName() { return $this->zipName; }

â†Šī¸ Returns

(string) ZIP file name