diff --git a/generate.php b/generate.php index 9c31c4005..b1b809ebb 100644 --- a/generate.php +++ b/generate.php @@ -8,19 +8,20 @@ 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(); @@ -28,7 +29,7 @@ header("Content-Disposition: attachment; filename=" . $response["promptDownloadFilename"] . ".zip"); readfile($zipPath); unlink($zipPath); - unlink($fileName); + unlink($filePath); exit; } } diff --git a/plugins/exportTypes/Excel/Excel.class.php b/plugins/exportTypes/Excel/Excel.class.php index 84d2f64bb..a227b78f5 100644 --- a/plugins/exportTypes/Excel/Excel.class.php +++ b/plugins/exportTypes/Excel/Excel.class.php @@ -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); @@ -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; } }