-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsvFileDownload.php
More file actions
30 lines (25 loc) · 936 Bytes
/
csvFileDownload.php
File metadata and controls
30 lines (25 loc) · 936 Bytes
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
<?php
session_start();
$serverName = "127.0.0.1"; //serverName\instanceName
$userName = "root";
$password = "";
//echo "csv";
if(isset($_POST['btnCsvFile'])){
$tbName = $_SESSION['tbName'];
$database = $_SESSION['db'];
$msqlConn = mysqli_connect($serverName, $userName, $password, $database);
if($msqlConn) {
//echo "Connection established.<br />";
$tb_info = mysqli_query($msqlConn, "SELECT * FROM ".$tbName);
header("content-type: csv");
header("content-Disposition: attachment; filename=".$database." ".$tbName.".csv");
$output = fopen("php://output", "w");
fputcsv($output,array('phoneNumber', 'message'));
while ($row = mysqli_fetch_assoc($tb_info)) {
$ary = array('0' =>$row['phoneNumber'] ,'1' =>$row['message'] );
fputcsv($output, $ary);
}
fclose($output);
}
}
?>