forked from danmed/TasmoBackupV1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
32 lines (25 loc) · 828 Bytes
/
export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?PHP
require(__DIR__.'/lib/functions.inc.php');
global $db_handle;
if ($_POST["export"]!="") {
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=tasmobackup_devices.csv');
//SQL Query for Data
$sql = "SELECT * FROM devices;";
//Prepare Query, Bind Parameters, Excute Query
$STH = $db_handle->prepare($sql);
$STH->execute();
//Export to .CSV
$fp = fopen('php://output', 'w');
// first set
$first_row = $STH->fetch(PDO::FETCH_ASSOC);
$headers = array_keys($first_row);
fputcsv($fp, $headers); // put the headers
fputcsv($fp, array_values($first_row)); // put the first row
while ($row = $STH->fetch(PDO::FETCH_NUM)) {
fputcsv($fp, $row); // push the rest
}
fclose($fp);
}
//header("Location: settings.php");
?>