2013-02-20 96 views
2

我要生成一個CSV文件到PHP輸出,使用戶可以立即下載:PHP://輸出中是無效

header('Content-Type: text/csv'); 
header('Content-Disposition: attachment; filename=' . $filename); 
$fp = fopen('php://ouput', 'w'); // Here is where error happens, line 156 
if(!$fp) var_dump($fp); // output: bool(false) 

,但它所產生的錯誤如下:

Warning: fopen(): Invalid php:// URL specified in /home/mustafa/xxx/includes/functions.php on line 156 
Warning: fopen(php://ouput): failed to open stream: operation failed in /home/mustafa/xxx/includes/functions.php on line 156 

爲什麼php://output無效

回答

2

改變這種

$fp = fopen('php://ouput', 'w'); 

$fp = fopen('php://output', 'w'); 
        ^// you missed `t` 
+1

哦,媽的,謝謝 – 2013-02-20 10:20:40

1

fopen()寫入到文件中。 php://ouput是無效的文件名/ URL。這是php://output,你錯過了't'。

如果要將輸出發送到客戶端(瀏覽器),只需使用echo打印數據即可。