1

I have this code, for example:

<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFromString('test.txt', 'file content goes here');
    echo 'ok';
} else {
    echo 'failed';
}
?>

It ends up saving ZIP file. I tried doing this:

echo $zip->addFromString('test.txt', 'file content goes here');

It just echoes 1 and saves it. (Maybe because I'm not providing headers?).

I want to provide zip as a download without saving it on the server.

EDIT: I tried providing some headers, but it ends up downloading as corrupted & it also ends up saving the zip.

NaMo
  • 513
  • 1
  • 6
  • 19

0 Answers0