我为joomla开发了扩展下载zip文件! 3.8。我已经创建了zip文件并在其中添加了一些文本文件。我想通过浏览器下载它,但我不能。请帮我! 我的代码:
$zipName = 'test.zip';
$zip = new ZipArchive;
$zip->open($zipName, ZipArchive::CREATE);
for($i = 0; $i < count($datas); $i++){
switch (strtoupper($filetype)){
case 'XLIFF':
$filenames[$i] = $filenames[$i].".xlf";
//create xliff file to add in zip file.
$this->createXLIFF($datas[$i], $header, $deduplicate, $sourcelanguage, $targetlanguage, $filenames[$i]);
$zip->addFile(realpath($filenames[$i]),$filenames[$i]);
break;
}
}
$zip->close();
@header("Content-Description: File Transfer");
@header("Content-Type: application/force-download");
@header("Content-Type: application/octet-stream");
@header("Content-Type: application/download");
@header("Content-Disposition: attachment; filename=\"".$zipName."\"");
@header("Content-Transfer-Encoding: binary");
@header("Pragma: public");
@header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
@header("Content-Length: ".filesize($zipName));
flush();
readfile($zipName);
unlink($zipName);
foreach ($filenames as $filename){
unlink($filename);
}
exit;
并输出: output in browser