Exemplo n.º 1
0
header("Content-Type: application/vnd.ms-excel");
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
/**
 * Escape CSV values
 *
 * @param string $value Original value to escape
 * @return string Escaped value
 **/
global $drainhole;
if ($type == 'stats') {
    $file = DH_File::get($id);
    header('Content-Disposition: attachment; filename="' . basename($file->file) . '.csv"');
    $stats = DH_Access::get_all($id);
    if (count($stats) > 0) {
        foreach ($stats as $stat) {
            $csv = array();
            $csv[] = $drainhole->csv_escape(date('Y-m-d', $stat->created_at));
            $csv[] = $drainhole->csv_escape(date('H:i', $stat->created_at));
            $csv[] = $drainhole->csv_escape($stat->ip);
            $csv[] = $drainhole->csv_escape($stat->speed);
            $csv[] = $drainhole->csv_escape($stat->time_taken);
            echo implode(',', $csv) . "\r\n";
        }
    }
} else {
    if ($type == 'files') {
        $hole = DH_Hole::get($id);
        header('Content-Disposition: attachment; filename="' . basename($hole->url) . '.csv"');