PHP-导出CSV文件
我写了一个脚本,它从Mysql数据库导出一个包含信息的CSV文件。此脚本在Linux服务器(Apache)下正常工作,但在Windows服务器(Apache)下无法工作 我认为这个标题的问题就在这里PHP-导出CSV文件,php,Php,我写了一个脚本,它从Mysql数据库导出一个包含信息的CSV文件。此脚本在Linux服务器(Apache)下正常工作,但在Windows服务器(Apache)下无法工作 我认为这个标题的问题就在这里 标题('Content-Type:text/x-csv'); 标题('Expires:'.gmdate('D,dm Y H:i:s')。'GMT'); 标题('Content-Disposition:attachment;filename=iBlock_download.csv'); 标题('Pra
标题('Content-Type:text/x-csv');
标题('Expires:'.gmdate('D,dm Y H:i:s')。'GMT');
标题('Content-Disposition:attachment;filename=iBlock_download.csv');
标题('Pragma:no cache');
标题(“内容类型:text/html;字符集=UTF-8”);
这里有人能帮忙吗
谢谢
脚本如下:
header('Content-Type: text/x-csv');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Content-Disposition: attachment; filename=iBlock_download.csv');
header('Pragma: no-cache');
header("Content-Type: text/html; charset=UTF-8");
include('./lib/sqlString.php');
$_id=$_GET['_id'];
$ResultPointer = mysql_query("SELECT * FROM projekte where pro_id='$_id'");
for($i = 0, $Export = ""; $i < mysql_num_rows($ResultPointer); $i++)
{
$Daten = mysql_fetch_object($ResultPointer);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_id);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_desc);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_exp);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_animal_nr);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_organ);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_treatment);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_comment);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_genotype);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_start_date);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_aktion);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_txt1);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_aktion);
$Spalte[] = str_replace("\"", "\"\"", $Daten->pro_user_name);
$ResultPointer2 = mysql_query("SELECT * FROM pro where fn_pro_id ='$Daten->pro_id'");
$sume=mysql_num_rows($ResultPointer2);
for($i = 0, $Export = ""; $i < mysql_num_rows($ResultPointer2); $i++)
{
$sume=mysql_num_rows($ResultPointer2);
$Daten2 = mysql_fetch_object($ResultPointer2);
$Spalte[] = str_replace("\"", "\"\"", $Daten2->fn_desc);
$Spalte[] = str_replace("\"", "\"\"", $Daten2->fn_order_date);
}
for($j = 0; $j < count($Spalte); $j++)
{
$Export .= "\"" . $Spalte[$j] . "\"";
if($j != count($Spalte)-1)
{
$Export .= ";";
}
}
$Export .= "\r\n";
$Spalte = "";
}
echo $Export;
标题('Content-Type:text/x-csv');
标题('Expires:'.gmdate('D,dm Y H:i:s')。'GMT');
标题('Content-Disposition:attachment;filename=iBlock_download.csv');
标题('Pragma:no cache');
标题(“内容类型:text/html;字符集=UTF-8”);
包括('./lib/sqlString.php');
$\u id=$\u GET[''u id'];
$ResultPointer=mysql\u查询(“从projekte中选择*,其中pro\u id='$\u id');
对于($i=0,$Export=“”;$ipro\u id);
$Spalte[]=str\u replace(“\”,“\”,$Daten->pro\u desc);
$Spalte[]=str\u replace(“\”,“\”,$Daten->pro\u exp);
$Spalte[]=str\u replace(“\”,“\”,$Daten->pro\u animal\u nr);
$Spalte[]=str\U替换(“\”、“\”、$Daten->pro\U器官);
$Spalte[]=str\U替换(“\”、“\”、$Daten->pro\U处理);
$Spalte[]=str\U替换(“\”、“\”、$Daten->pro\U注释);
$Spalte[]=str\U替换(“\”、“\”、$Daten->pro\U基因型);
$Spalte[]=str\u replace(“\”,“\”,$Daten->pro\u start\u date);
$Spalte[]=str\u replace(“\”、“\”、$Daten->pro\u aktion);
$Spalte[]=str\u replace(“\”,“\”,$Daten->pro\u txt1);
$Spalte[]=str\u replace(“\”、“\”、$Daten->pro\u aktion);
$Spalte[]=str\u replace(“\”、“\”、$Daten->pro\u用户名);
$ResultPointer2=mysql\u查询(“选择*FROM pro,其中fn\u pro\u id='$Daten->pro\u id'”);
$sume=mysql\u num\u行($ResultPointer2);
对于($i=0,$Export=“”;$ifn\u desc);
$Spalte[]=str\u replace(“\”,“\”,$Daten2->fn\u order\u date);
}
对于($j=0;$j
首先…不知道脚本是如何实现的,但在使用csv时,这是一个非常有用的函数。()
然而,为什么你们有两个定义内容类型的标题函数呢?文本/html是不需要的,我只会坚持使用
header('Content-Type: text/csv');
或
首先,你有两个
内容类型
标题。我会去掉最后一个。谢谢你的回答。问题已经解决了。问题在第一个脚本上。我有“
header('Content-Type: text/plain');