1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
public function executeListZip(sfWebRequest $request)
{
// create object
$zipfile = 'php://temp/';
$zip = new ZipArchive;
// open archive
if ($zip->open($zipfile, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// list of files to add
$fileList = array(
'test.pdf',
);
// add files
foreach ($fileList as $f) {
$zip->addFile($f) or die ("ERROR: Could not add file: $f");
}
// close and save archive
$zip->close();
//Export the output
$this->getResponse()->clearHttpHeaders();
$this->getResponse()->setHttpHeader('Content-type', 'application/zip');
$this->getResponse()->setHttpHeader('Content-disposition','attachment; filename="archive.zip"');
$this->getResponse()->sendHttpHeaders();
$this->getResponse()->setContent(readfile($zipfile));
$this->getResponse()->sendContent();
return sfView::NONE;
} |
Partager