2011-06-30 104 views
3

在我的系統中,我已經獲取所有數據並導出到txt文件中。PHP頭問題

$str_res_exp = $this->export_res($column ,$res_data,$column_length); 
header("Content-type: plain/text"); 
header("Content-Disposition: attachment; filename=".$_POST['txt_name'].".txt"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
echo $str_res_exp; 
exit; 

它顯示的數據,但是,但是,第一行,第一個字符它填補空白......

由於安全原因,我不能發佈更多的代碼。

+3

是的,你可以發佈更多的代碼,只是放入一些示例數據。我相信你的錯誤是在你的export_res方法 – Ibu

+1

你試過'回調修剪($ str_res_exp);退出;'? –

+1

您是否檢查過您的文檔在php標籤之前不包含任何空格?並使用@Shakti Singh的代碼作爲預防措施 –

回答

0

試試這個:

ob_start(); // put this at the beginning of your scripts 

$str_res_exp = $this->export_res($column ,$res_data,$column_length); 
header("Content-type: plain/text"); 
header("Content-Disposition: attachment; filename=".$_POST['txt_name'].".txt"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
ob_end_clean(); 
echo $str_res_exp; 
exit; 

什麼類型的服務器,您使用的?