Re: [請益] 請問下載檔案

看板PHP作者 (不小的挑戰)時間13年前 (2012/09/14 17:50), 編輯推噓0(005)
留言5則, 5人參與, 最新討論串3/3 (看更多)
感謝C大回覆 但是我輸出的CSV都是網頁原始檔 比如說程式碼是 <html> <head> <title>測試</title> </head> <body> <form name="form1" method="post" action=""> <input type="submit" name="button2" id="button2" value="送出"> </form> </body> </html> <?php if(isset($_POST['button2'])){ $F=date ('md'); $Wr=fopen('php://output','w+'); fputcsv($Wr,array('編號','名稱','製作員','尺寸','出廠日','製作日期','製作時間')); header("Content-type:text/x-csv"); header("Content-Disposition:attachment;filename=$F.csv"); }?> ==== 輸出的CSV 變成 編號,名稱,製作員,尺寸,出廠日,製作日期,製作時間 <head> <title>測試</title> </head> <body> <form name="form1" method="post" action=""> <input type="submit" name="button2" id="button2" value="送出"> </form> </body> </html> 請問哪裡出錯了~謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.63.34.193

09/14 17:59, , 1F
你跟本搞錯header的意思...
09/14 17:59, 1F

09/14 23:31, , 3F
header前面不能有任何的輸出....
09/14 23:31, 3F

09/16 21:31, , 4F
你的action要指到另一個專門產生csv檔的程式啦
09/16 21:31, 4F

09/17 01:01, , 5F
謝謝各位大大,已解決
09/17 01:01, 5F
文章代碼(AID): #1GKltPBt (PHP)
文章代碼(AID): #1GKltPBt (PHP)