note 84646 modified in function.ziparchive-open by danbrown
| From: | danbrown@php.net | Date: | Wed, 23 Jul 2008 16:14:14 +0000 |
| Subject: | note 84646 modified in function.ziparchive-open by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142621@lists.php.net to get a copy of this message | ||
The file name does not need to end in '.zip' if it is created using tempnam(). You just
need to overwrite the file instead of trying to read it:
<?php
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
// Zip will open and overwrite the file, rather than try to read it.
$zip->open($file, ZipArchive::OVERWRITE);
$zip->close();
// Stream the file to the client
header("Content-Type: application/zip");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"a_zip_file.zip\"");
readfile($file);
unlink($file);
?>
--was--
The file name does not need to end in '.zip' if it is created using tempnam(). You just
need to overwrite the file instead of trying to read it:
$file = tempnam("tmp", "zip");
$zip = new ZipArchive();
// Zip will open and overwrite the file, rather than try to read it.
$zip->open($file, ZipArchive::OVERWRITE);
$zip->close();
// Stream the file to the client
header("Content-Type: application/zip");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"a_zip_file.zip\"");
readfile($file);
unlink($file);
http://php.net/manual/en/function.ziparchive-open.php