From 551047edb67717d5e03f719dbff2c8699b7126be Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 25 Oct 2017 15:50:27 -0400 Subject: [PATCH] add check for empty post --- export.php | 13 ++++++++----- export.xlsx => template.xlsx | Bin ~$export.xlsx | Bin 165 -> 0 bytes 3 files changed, 8 insertions(+), 5 deletions(-) rename export.xlsx => template.xlsx (100%) delete mode 100755 ~$export.xlsx diff --git a/export.php b/export.php index 21b29a9..6ba6242 100644 --- a/export.php +++ b/export.php @@ -2,15 +2,18 @@ require_once __DIR__ . "/vendor/autoload.php"; +if (empty($_POST["test_cases"])) { + header("Location: /~ben/testgen/"); + die(); +} -$excel = PHPExcel_IOFactory::load("export.xlsx"); - +// split input by line and place into template at cell B2 $cases = explode("\n", $_POST["test_cases"]); +$excel = PHPExcel_IOFactory::load("template.xlsx"); $excel->getActiveSheet()->fromArray(array_chunk($cases, 1), NULL, 'B2'); +// set the right download headers header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="testcase-template.xls"'); header('Cache-Control: max-age=0'); -$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); -$writer->save('php://output'); - +PHPExcel_IOFactory::createWriter($excel, 'Excel5')->save('php://output'); diff --git a/export.xlsx b/template.xlsx similarity index 100% rename from export.xlsx rename to template.xlsx diff --git a/~$export.xlsx b/~$export.xlsx deleted file mode 100755 index ccf2a80e22215d62cd6c8e294a0ac4035f6d23c9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 165 scmd;bO3hR7NGvMKELI=^a4|SBq%!0&C@^?1Br+5MVJ1T{kVhK`0DhwqQ2+n{