RelatorioCSV.php
982 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
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once('Relatorio.php');
class RelatorioCSV extends Relatorio
{
public function output()
{
$buffer = "";
//Data
foreach ($this->getBody() as $row)
{
$line = array();
foreach ($row as $cell)
{
$line[] = '"'.str_replace('"', '""', iconv('utf-8' ,'iso-8859-1', $this->relstrip($cell))).'"';
}
$buffer .= implode(",", $line) . "\r\n";
}
if (ob_get_contents())
{
die('Saída já iniciada, impossível emitir CSV: ['.ob_get_contents().']');
}
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'],'MSIE'))
{
header('Content-Type: application/force-download');
}
else
{
header('Content-Type: application/octet-stream');
}
if (headers_sent())
{
die('Saída já iniciada, impossível emitir CSV.');
}
header('Content-Length: '.strlen($buffer));
header('Content-disposition: attachment; filename="relatorio.csv"');
echo $buffer;
}
}
?>