|
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 |
| -?> |
| 1 | +<!DOCTYPE html><head> |
| 2 | +<meta charset="utf-8"> |
| 3 | +<title>Orders Table</title> |
| 4 | +<script src="jquery-1.9.0.min.js"></script> |
| 5 | +<script> |
| 6 | +$(document).ready(function(e) { |
| 7 | + $("button").on('click',function(e){ |
| 8 | + if($('input[type=file]').val()!=""){ |
| 9 | + var file = $('input[type=file]')[0].files[0].name; |
| 10 | + var ext = file.split('.').pop().toLowerCase(); |
| 11 | + if($.inArray(ext, ['csv']) == -1) { |
| 12 | + alert('invalid extension!'); |
| 13 | + }else{ |
| 14 | + window.location = 'upload.php?csv='+file; |
| 15 | + } |
| 16 | + |
| 17 | + |
| 18 | + } |
| 19 | + return false; |
| 20 | + }); |
| 21 | +}); |
| 22 | +</script> |
| 23 | +</head> |
| 24 | + |
| 25 | + |
| 26 | +<input type="file" name="csv" value="" /> |
| 27 | +<button>Export now!</button> |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
0 commit comments