每当我要下载自己的csv数据时,它都会下载整个代码,而不是以一种很好的形式下载数据,它总是向我输出整个代码,该怎么做,一旦在浏览器中这样显示browser-image,然后下载的文件downloaded-file
我的方法是导入一个首先与y数据库记录匹配的csv数据,然后将输出作为匹配数据提供,现在我想将该匹配数据下载为csv。格式,并以适当的方式(例如行和所有记录)作为标题,但它始终以csv格式下载代码。
$keyword = $_POST['keyword']; $csvname = $_POST['csv_file'];
header("Content-type: text/csv");
header("Content-disposition: attachment; filename = idata.csv");
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('url', 'id', 'title'));
?>
<table border ="1">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>count</th>
</tr>
</thead>
<?php
$row = 0;
if (($handle = fopen("idata.csv", "r",)) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
// echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
// echo $data[$c] . "<br />\n";
$query = "SELECT * FROM wm_article WHERE id = '".$data[$c]."'";
$exec = mysqli_query($conn, $query);
$details = mysqli_fetch_array($exec);
$description = $details['title'] ." ".$details['description'];
//echo $description ;
// $regex = "/royal/";
// if (preg_match_all($regex, $description, $match))
// {
// print_r ($matches[0]);
// }
if(preg_match_all("/\b".$keyword."\b/i", $description, $match,PREG_OFFSET_CAPTURE, 3)){
// echo count(explode('royal', $description));
// echo "<pre>";print_r($match);
// echo implode(",", $data)."\n";
?>
<tr>
<td><?php echo $details['id'];?></td>
<td><a href ="<?php echo $details['url'];?>" target ="_blank"><?php echo $details['title'];?></a></td>
<td><?php echo count($match[0]); ?></td>
</tr>
<?php
}
}
}
fclose($handle);
}
?>
</table>