可能重复:
PHP 已发送的标头
将 mysql 表转换为 .CSV 文件的 PHP 脚本给出了无法修改标头信息和不将数据写入 CSV 文件等错误:
以下是错误:
警告:无法修改标头信息 - 标头已由第 30 行 /home/public_html/amgtst/export-tst.php 中的(输出开始于 /home/public_html/amgtst/export-tst.php:3)发送
警告:无法修改标头信息 - 标头已由第 31 行 /home/public_html/amgtst/export-tst.php 中的(输出开始于 /home/public_html/amgtst/export-tst.php:3)发送
警告:无法修改标头信息 - 标头已由第 32 行 /home/public_html/amgtst/export-tst.php 中的(输出开始于 /home/public_html/amgtst/export-tst.php:3)发送
警告:无法修改标头信息 - 标头已由第 33 行 /home/public_html/amgtst/export-tst.php 中的(输出开始于 /home/public_html/amgtst/export-tst.php:3)发送
Area Area DC_No Area DC_No Product_type Area DC_No Product_type DC_date Area DC_No Product_type DC_date Ac_code Area DC_No Product_type DC_date Ac_code PO_No Area DC_No Product_type DC_date Ac_code PO_No PO_date Area DC_No Product_type DC_date Ac_code PO_No PO_date Inv_No Area DC_No Product_type DC_date Ac_code PO_No PO_date Inv_No CNo_Qty Area DC_No Product_type DC_date Ac_code PO_No PO_date Inv_No CNo_Qty Deleted Area DC_No Product_type DC_date Ac_code PO_No PO_date Inv_No CNo_Qty Deleted Vehicle_no Area DC_No Product_type DC_date Ac_code PO_No PO_date Inv_No CNo_Qty Deleted Vehicle_no "Jayanagar" "100" "Gas" "2012-11-30" "2" "2012-11-30" "11" "KA123-333" "Jayanagar" "104" "Gas" "2012-12-03" "3" "2012-12-03" "14" "Jayanagar" "101" "Gas" "2012-12-03" "3" "2012-12-03" "13" "Jayanagar" "105" "Gas" "2012-12-03" "3" "2012-12-03" "17" "Jayanagar" "106" "Gas" "2012-12-03" "3" "2012-12-03" "16" "Jayanagar" "107" "Gas" "2012-12-03" "3" "2012-12-03" "KA576" "Jayanagar" "108" "Gas" "2012-12-03" "2" "2012-12-03" "25" "KA01P213" "Jayanagar" "111" "Gas" "2012-12-04" "2" "2012-12-04" "27" "Jayanagar" "125" "Gas" "2012-12-04" "3" "2012-12-04" "12" "Jayanagar" "116" "Gas" "2012-12-06" "2" "2012-12-06" "Jayanagar" "117" "Gas" "2012-12-06" "2" "2012-12-06" "19" "Jayanagar" "118" "Gas" "2012-12-06" "2" "2012-12-06" "20" "Jayanagar" "119" "Gas" "2012-12-06" "2" "2012-12-06" "21" "Jayanagar" "130" "Gas" "2012-12-06" "3" "2012-12-06" "22" "KA-01-A4564" "Jayanagar" "131" "Gas" "2012-12-08" "2" "2012-12-08" "23" "KA01-23212" "Jayanagar" "132" "Gas" "2012-12-08" "2" "PIA-234234-ERES" "2012-12-08" "24" "KA-10-23232" "Jayanagar" "133" "Gas" "2012-12-08" "2" "verbal" "2012-12-08" "26" "ka91901212"
我的php脚本:
<?php
include 'dbconnect.php';
echo "Exporting file - process"."<br><br>";
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=download.csv");
header("Pragma: no-cache");
header("Expires: 0");
$query = "SELECT * FROM DCHDR";
$export = mysql_query ($query ) or die ( "Sql error : " . mysql_error( ) );
$fields = mysql_num_fields ( $export );
for ( $i = 0; $i < $fields; $i++ )
{
$header .= mysql_field_name( $export , $i ) . "\t";
echo $header;
}
while( $row = mysql_fetch_row( $export ) )
{
$line = '';
foreach( $row as $value )
{
if ( ( !isset( $value ) ) || ( $value == "" ) )
{
$value = "\t";
}
else
{
$value = str_replace( '"' , '""' , $value );
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim( $line ) . "\n";
}
$data = str_replace( "\r" , "" , $data );
if ( $data == "" )
{
$data = "\n(0) Records Found!\n";
}
print "$header\n$data";
exit();
php?>