Skip to content

Commit 625a2b7

Browse files
committed
Create etsy_csv_export.php
1 parent a62adb9 commit 625a2b7

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

etsy_csv_export.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/*
3+
This file will generate our CSV table. There is nothing to display on this page, it is simply used
4+
to generate our CSV file and then exit. That way we won't be re-directed after pressing the export
5+
to CSV button on the previous page.
6+
*/
7+
//First we'll generate an output variable called out. It'll have all of our text for the CSV file.
8+
$out = '';
9+
//Next let's initialize a variable for our filename prefix (optional).
10+
$filename_prefix = 'csv';
11+
//Next we'll check to see if our variables posted and if they did we'll simply append them to out.
12+
if (isset($_POST['csv_hdr'])) {
13+
$out .= $_POST['csv_hdr'];
14+
$out .= "\n";
15+
}
16+
if (isset($_POST['csv_output'])) {
17+
$out .= $_POST['csv_output'];
18+
$out .= "\n";
19+
}
20+
//Now we're ready to create a file. This method generates a filename based on the current date & time.
21+
$filename = $filename_prefix."_".date("Y-m-d_H-i",time());
22+
//Generate the CSV file header
23+
header("Content-type: application/vnd.ms-excel");
24+
header("Content-Encoding: UTF-8");
25+
header("Content-type: text/csv; charset=UTF-8");
26+
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
27+
header("Content-disposition: filename=".$filename.".csv");
28+
echo "\xEF\xBB\xBF"; // UTF-8 BOM
29+
//Print the contents of out to the generated file.
30+
echo $out;
31+
//Exit the script
32+
exit;
33+
?>

0 commit comments

Comments
 (0)