Laravel 3创建文本(CSV)文件

Hello I am trying to grab all the emails from the database, then output them into a text (comma separated) file. Here is what I have done but does not work:

public function get_textfile() {

$emails = Staff::get('email');

header("Content-type: text/csv");  
header("Cache-Control: no-store, no-cache");  
header('Content-Disposition: attachment; filename="filename.txt"');

$stream = fopen("php://output", 'w');

foreach($emails as $email) {
fputcsv($stream, $email, ',');
}

fclose($outstream);     
}

return (something)?

getting this: Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.

This is my route:

    Route::get('textfile', array('as' => 'textfile','uses' => 'admin@textfile'));

try file_put_contents($filename, implode(',', Staff::get('email')));

Collect all of your data into a string and then output it like this:

$data = '';
foreach ($emails as $email)
{
    // If you want 1 email per line
    $data .= '"'.$email.'"'.PHP_EOL;

    // If you want all emails on 1 line
    $data .= '"'.$email.'",';
}

header('Content-type: text/csv');
header('Content-Disposition: attachment; filename=My Cool File.csv');
header('Pragma: no-cache');
header('Expires: 0');

echo $data;