Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #362 from derdeagle/master
Fix for issue #360
  • Loading branch information
benkeen committed Feb 13, 2016
2 parents 9a19ff1 + 2693386 commit f48960a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions generate.php
Expand Up @@ -8,27 +8,28 @@

if ($gen->getExportTarget() == "promptDownload") {
header("Cache-Control: private, no-cache, must-revalidate");

// check if user opted to zip the generated data
if ($gen->isPromptDownloadZipped()) {
$randNum = mt_rand(0, 100000000);
$fileName = $randNum . "_" . $response["promptDownloadFilename"];
$filePath = "./cache/" . $fileName;
$zipPath = "./cache/" . $fileName . ".zip";

if (file_put_contents($fileName, $response["content"])) {
if (file_put_contents($filePath, $response["content"])) {

// now that we've written the file, zip it up
$zip = new ZipArchive();
$zipFile = $zip->open($zipPath, ZipArchive::CREATE);
if ($zipFile && $zip->addFile($fileName, $response["promptDownloadFilename"])) {
if ($zipFile && $zip->addFile($filePath, $response["promptDownloadFilename"])) {

// we've got our zip file now we may set the response header
$zip->close();
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=" . $response["promptDownloadFilename"] . ".zip");
readfile($zipPath);
unlink($zipPath);
unlink($fileName);
unlink($filePath);
exit;
}
}
Expand Down
13 changes: 7 additions & 6 deletions plugins/exportTypes/Excel/Excel.class.php
Expand Up @@ -48,13 +48,14 @@ function generate($generator) {

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
//get the name of the save file
$filepath=$this->getDownloadFilename($generator);
$filename=$this->getDownloadFilename($generator);
$filepath="./cache/" . $filename;
//save the excel data to that file
$objWriter->save($filepath);
if (!($generator->isPromptDownloadZipped())) {
// redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="' . $filepath . '"');
header('Content-Disposition: attachment;filename="' . $filename . '"');
header('Cache-Control: max-age=0');
readfile($filepath);
@unlink($filepath);
Expand All @@ -64,15 +65,15 @@ function generate($generator) {
$zip = new ZipArchive();
$zipfile = $zip->open($zippath, ZipArchive::CREATE);
if ($zipfile) {
if ($zip->addFile($filepath, $filepath)) {
if ($zip->addFile($filepath, $filename)) {
//we've got our zip file now we may set the response header
$zip->close();
header("Cache-Control: private, no-cache, must-revalidate");
header("Content-type: application/zip");
header('Content-Disposition: attachment; filename="' . $filepath . '.zip"');
header("Content-type: application/zip");
header('Content-Disposition: attachment; filename="' . $filename . '.zip"');
readfile($zippath);
unlink($zippath);
unlink($filepath);
unlink($filename);
exit;
}
}
Expand Down

0 comments on commit f48960a

Please sign in to comment.