【发布时间】:2015-07-09 22:12:40
【问题描述】:
我使用 Joomla 3.x 作为我的网站内容管理器,还使用 NoNumber sourcerer 扩展,它允许我将 PHP 代码放置在我的文章中的任何位置。我使用 ZipArchive 压缩选定的文件并将它们下载为 .zip。但是,下载 zip 文件时会损坏,因为在文本编辑器中查看时,您可以从 Joomla 框架中看到文章周围的所有 HTML。有没有办法解决???我已经为此苦苦挣扎了一段时间,我们将不胜感激。
下面是 sourcerer 标签之间的结尾:
require_once("../php/Archive/Zip.php");
if((!empty($_POST['showdate']) || isset($_POST['showdate'])) && (!empty($_POST['showsheets']) || isset($_POST['showsheets'])) )
{
// echo $_POST['showdate'];
// foreach($_POST['showsheets'] as $showsheet)
// {
// echo $showsheet;
// }
$files = $_POST['showsheets'];
unset($_POST['showsheets']);
$zippath = 'jdownloads/tmp/';
$zipname = $_POST['showdate'].'ShowSheets.zip';
unset($_POST['showdate']);
//$regex = "/^Jan | ^June | ^Sept/";
foreach( new DirectoryIterator($zippath) as $fileInfo ){
if( $fileInfo->isDot() || !$fileInfo->isFile() || $fileInfo->getFilename() == 'index.html' )
continue;
// if (preg_match($regex, $fileInfo->getFilename())) {
unlink($fileInfo->getPathname());
// }
}
$zip = new ZipArchive;
$zip->open($zippath . $zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
//$content = file_get_contents($file);
//$zip->addFromString(pathinfo ( $file, PATHINFO_BASENAME), $content);
}
$zip->close();
// header('Content-Type: application/zip');
// header('Content-disposition: attachment; filename='.$zipname);
// header('Content-Length: ' . filesize($zippath . $zipname));
// readfile($zippath . $zipname);
// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$zipname."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($zippath . $zipname));
//ob_end_flush();
readfile($zippath . $zipname);
}
?>
Windows 资源管理器只是告诉我它是空的,尝试提取告诉我它无效,7zip 可以得到里面的东西,但实际的 .xlsx 文件已损坏,它无法对它们做任何事情。
这是在文本编辑器中查看示例文件时生成的内容:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="http://wheatbeltusa.com/index.php/testing-one" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="Super User" />
<meta name="description" content="Farm and Home Supplies" />
<meta name="generator" content="Joomla! - Open Source Content Management" />
<title>Testing One - Wheatbelt Inc.</title>
<link href="http://wheatbeltusa.com/index.php/testing-one" rel="canonical" />
<link href="/templates/protostar/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />
<link rel="stylesheet" href="/templates/protostar/css/template.css" type="text/css" />
<link rel="stylesheet" href="/media/system/css/frontediting.css" type="text/css" />
<script src="/media/jui/js/jquery.min.js" type="text/javascript"></script>
<script src="/media/jui/js/jquery-noconflict.js" type="text/javascript"></script>
<script src="/media/jui/js/jquery-migrate.min.js" type="text/javascript"></script>
<script src="/media/system/js/caption.js" type="text/javascript"></script>
<script src="/media/jui/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/media/system/js/frontediting.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(window).on('load', function() {
new JCaption('img.caption');
});
jQuery(document).ready(function(){
jQuery('.hasTooltip').tooltip({"html": true,"container": "body"});
});
jQuery(document).ready(function()
等...后面是我想要的所有二进制文件,然后是更多joomla html页脚和(你明白了)
那么,ppl 如何在 joomla 中制作 zip 文件并包含要下载的文件头而不被它破坏?
感谢您的帮助
【问题讨论】:
标签: php joomla zip ziparchive