File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+
8
+ //First we'll generate an output variable called out. It'll have all of our text for the CSV file.
9
+ $ out = '' ;
10
+
11
+ //Next let's initialize a variable for our filename prefix (optional).
12
+ $ filename_prefix = 'csv ' ;
13
+
14
+ //Next we'll check to see if our variables posted and if they did we'll simply append them to out.
15
+ if (isset ($ _POST ['csv_hdr ' ])) {
16
+ $ out .= $ _POST ['csv_hdr ' ];
17
+ $ out .= "\n" ;
18
+ }
19
+
20
+ if (isset ($ _POST ['csv_output ' ])) {
21
+ $ out .= $ _POST ['csv_output ' ];
22
+ $ out .= "\n" ;
23
+ }
24
+
25
+ //Now we're ready to create a file. This method generates a filename based on the current date & time.
26
+ $ filename = $ filename_prefix ."_ " .date ("Y-m-d_H-i " ,time ());
27
+
28
+ //Generate the CSV file header
29
+ header ("Content-type: application/vnd.ms-excel " );
30
+ header ("Content-Encoding: UTF-8 " );
31
+ header ("Content-type: text/csv; charset=UTF-8 " );
32
+ header ("Content-disposition: csv " . date ("Y-m-d " ) . ".csv " );
33
+ header ("Content-disposition: filename= " .$ filename .".csv " );
34
+ echo "\xEF\xBB\xBF" ; // UTF-8 BOM
35
+ //Print the contents of out to the generated file.
36
+ echo $ out ;
37
+
38
+ //Exit the script
39
+ exit ;
40
+ ?>
You can’t perform that action at this time.
0 commit comments