joomla ZipArchive生成无效的zip文件

问题描述:

Im使用Joomla 3.x作为我的网站内容管理器,并且还使用了NoNumber sourcerer扩展,它允许我在我的文章中的任何位置放置PHP代码。我使用ZipArchive压缩选定的文件并将其下载到.zip中。但是,当下载的zip文件被破坏时,因为在文本编辑器中查看时,您可以看到Joomla Framework中文章的所有HTML。有没有办法解决???我一直在努力,现在有一段时间了,任何帮助,将不胜感激。joomla ZipArchive生成无效的zip文件

这里是什么放在源码人员标签之间到底:

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资源管理器只是告诉我它的空,并试图toextract告诉我,它的无效和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文件,并包括他们的头被下载,而不是由此?

感谢所有帮助

OMG,

我只是通过剥离最终实现>并添加退出?;在读取文件之后立即转义它。如:

ob_clean(); 
flush(); 

readfile($filepath); 

exit; 
}