| 1 |
<?php |
| 2 |
require_once('../../../wp-config.php'); |
| 3 |
|
| 4 |
if(!defined('ABSPATH')) |
| 5 |
die('Forbidden'); |
| 6 |
|
| 7 |
if(!current_user_can('manage_options')) |
| 8 |
die('Forbidden'); |
| 9 |
|
| 10 |
|
| 11 |
$data=GetPostValue("exportdata"); |
| 12 |
$json=json_decode($data,true); |
| 13 |
|
| 14 |
header('Content-Encoding: UTF-8'); |
| 15 |
header('Content-type: text/csv; charset=UTF-8'); |
| 16 |
header('Content-Disposition: attachment; filename=Export.csv'); |
| 17 |
|
| 18 |
if(count($json)<=0) |
| 19 |
die(); |
| 20 |
$keys=array_keys($json[0]); |
| 21 |
$firstColumn=true; |
| 22 |
foreach($keys as $header) |
| 23 |
{ |
| 24 |
if(!$firstColumn) |
| 25 |
echo ","; |
| 26 |
$firstColumn=false; |
| 27 |
echo '"'.$header.'"'; |
| 28 |
} |
| 29 |
foreach($json as $row) |
| 30 |
{ |
| 31 |
$firstColumn=true; |
| 32 |
echo "\r\n"; |
| 33 |
foreach($row as $column) |
| 34 |
{ |
| 35 |
if(!$firstColumn) |
| 36 |
echo ","; |
| 37 |
$firstColumn=false; |
| 38 |
echo '"'.$column.'"'; |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
echo "\xEF\xBB\xBF"; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|