<?php $list = array( array("A1","B1","C1"), array("A2","B2","C2") ); $filename = date("Y-m-d") . ".csv"; $f = fopen('php://memory', 'w'); // 寫入 php://memory foreach ($list as $row) { fputcsv($f, $row); } fseek($f, 0); header('Content-Type: application/csv'); header('Content-Disposition: attachement; filename="' . $filename . '"'); fpassthru($f);
參考:
http://www.php.net/manual/en/wrappers.php.php (php://)
http://stackoverflow.com/questions/16251625/how-to-create-and-download-a-csv-file-from-php-script
沒有留言:
張貼留言