fp = fopen("php://temp", "w+"); $this->header_added = false; } public function __destruct() { fclose($this->fp); } public function addHeader(array $data) { if (!$this->header_added) { if (fputcsv($this->fp, $data)) { $this->header_added = true; return true; } } return false; } public function addDataRow(array $data) { return fputcsv($this->fp, $data); } public function getData() { rewind($this->fp); return stream_get_contents($this->fp); } }