Script PHP Untuk Download CSV
Script yang saya tulis dibawah ini digunakan untuk mengexport dengan tipe download file csv. Jika anda hanya mengelink kan ke file csv maka data akan dibukan di browser tapi bukan didownload. Oke berikut scriptnya.
//NAME THE FILE $table = "test"; //BUILD CSV CONTENT $csv = '"Column 1","Column 2"' . "\n"; //BUILD CSV ROWS $csv .= '"Column 1 Content","Column 2 Content"' . "\n"; $csv .= '"Column 1 Content","Column 2 Content"' . "\n"; $csv .= '"Column 1 Content","Column 2 Content"' . "\n"; $csv .= '"Column 1 Content","Column 2 Content"' . "\n"; $csv .= '"Column 1 Content","Column 2 Content"' . "\n"; //OUPUT HEADERS header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"$table.csv\";" ); header("Content-Transfer-Encoding: binary"); //OUTPUT CSV CONTENT echo($csv);Sumber : http://www.ziplineinteractive.com/blog/proper-php-headers-for-csv-documents-all-browsers/
Tidak ada komentar:
Posting Komentar