-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcsv.php
More file actions
58 lines (50 loc) · 1.43 KB
/
csv.php
File metadata and controls
58 lines (50 loc) · 1.43 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
The CSV generating code here is a modified version of Jrgns's code:
https://stackoverflow.com/a/125578
*/
include ("config.php");
if ($debug){
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 1);
}
session_start();
include ("config.php");
include ("mysql_connect.php");
if (isset($_SESSION['weed_table']) &! isset($_REQUEST['table'])) {
$_REQUEST['table'] = $_SESSION['weed_table'];
}
elseif (isset($_REQUEST['table'])) {
$_SESSION['weed_table'] = $_REQUEST['table'];
}
$table = $_REQUEST['table'];
$output = "";
if (isset($_REQUEST['copytwo']) && ($_REQUEST['copytwo'] == true)) {
$whereCopyTwo = "WHERE call_bib IN (SELECT * FROM (SELECT `call_bib` FROM $_SESSION[weed_table] Group by `call_bib` having count(*)> 1 ) AS subquery)";
}
else {
$whereCopyTwo = '';
}
$q = "SELECT * FROM `$table` $whereCopyTwo";
$stmt = $db->query($q);
$headers = array();
$headers_meta = array();
for ($i = 0; $i < $stmt->columnCount(); $i++) {
$headers_meta[] = $stmt->getColumnMeta($i);
}
foreach ($headers_meta as $h) {
array_push($headers, $h['name']);
}
$fp = fopen('php://output', 'w');
if ($fp && $stmt) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="'.$table.'.csv"');
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
fputcsv($fp, array_values($row));
}
die;
}
?>