2013-05-07 42 views
0
header('Content-type: text/csv'); 
    header('Content-Disposition: attachment; filename="file.csv"'); 

    echo "blabla"; 

    $Email = new CakeEmail(); 
    $Email->from(array('[email protected]' => 'Something')); 
    $Email->to($email); 
    $Email->subject('Something'); 
    $Email->send($textEmail); 

如何在發送電子郵件前輸出並下載文件?可能嗎?或者我必須爲自己創建一個臨時文件?如果我不發送電子郵件,它會起作用。輸出後關閉標題

+0

您使用的是什麼版本的CakePHP? – thaJeztah 2013-05-07 21:05:32

+0

@thaJeztah最新 – 2013-05-07 23:58:09

回答

1

一種解決方案可能是:

  1. 創建文件並將其保存到一個tempoary位置
  2. 發送電子郵件附件(使用你在你的問題發佈的代碼)
  3. 使用低水平PHP方法寫入文件內容HTTP流(see this answer
  4. 最後,刪除tempoary文件

我認爲從你發佈的代碼的外觀來看,你幾乎就在那裏,只需將訂單排序。

我希望這會有所幫助。