add check for empty post
This commit is contained in:
parent
ad2f5eca85
commit
551047edb6
13
export.php
13
export.php
|
@ -2,15 +2,18 @@
|
||||||
|
|
||||||
require_once __DIR__ . "/vendor/autoload.php";
|
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"]);
|
$cases = explode("\n", $_POST["test_cases"]);
|
||||||
|
$excel = PHPExcel_IOFactory::load("template.xlsx");
|
||||||
$excel->getActiveSheet()->fromArray(array_chunk($cases, 1), NULL, 'B2');
|
$excel->getActiveSheet()->fromArray(array_chunk($cases, 1), NULL, 'B2');
|
||||||
|
|
||||||
|
// set the right download headers
|
||||||
header('Content-Type: application/vnd.ms-excel');
|
header('Content-Type: application/vnd.ms-excel');
|
||||||
header('Content-Disposition: attachment;filename="testcase-template.xls"');
|
header('Content-Disposition: attachment;filename="testcase-template.xls"');
|
||||||
header('Cache-Control: max-age=0');
|
header('Cache-Control: max-age=0');
|
||||||
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
|
PHPExcel_IOFactory::createWriter($excel, 'Excel5')->save('php://output');
|
||||||
$writer->save('php://output');
|
|
||||||
|
|
||||||
|
|
BIN
~$export.xlsx
BIN
~$export.xlsx
Binary file not shown.
Loading…
Reference in New Issue