php - joomla ZipArchive producing invalid zip files -


im using joomla 3.x website content manager , using nonumber sourcerer extension allows me place php code anywhere in articles. im using ziparchive zip selected files , download them in .zip. however, when downloaded zip file becomes corrupted because when viewed in text editor can see of html surrounding article joomla framework. there anyway around this??? ive been struggling while , appreciated.

here end of placed between sourcerer tags:

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'] $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) $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 $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 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 explorer tell me empty , trying toextract tells me invalid , 7zip can whats inside actual .xlsx files corrupter , cant them.

this produced sample file when looking @ in text editor:

<!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 , home supplies" />   <meta name="generator" content="joomla! - open source content management" />   <title>testing 1 - 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() 

etc... followed binary want followed more joomla html footers , (you idea)

so how ppl make zip files in joomla , include headers them downloaded , not corrupted this?

thanks help

omg,

i realized stripping final ?> , adding exit; right after readfile escapes it. such as:

ob_clean(); flush();  readfile($filepath);  exit; } 

Comments