我需要带有列标题和逗号分隔数据的csv输出。 fputcsv
函数正常工作,只是它在输出文件的顶部放置了一个“验证”注释:
<!-- Validated at 2016-04-17 00:32:00 -->
此行会在更新数据时导致文件失败。如果我删除评论,该文件工作。有没有人知道如何在没有注释行的情况下生成fputcsv
输出?
这是代码
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=gmail.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Name', 'Given Name', 'Family Name', 'Group Membership', 'E-mail 1 - Value'));
// Connect to host and open db
include('includes/connect.php');
//Set Date range. Determines current renewal year for Select statement
$year = date('Y') - 1;
$group = date('Y')." member";
/* Select specified member data */
$sql = "SELECT firstLast, firstName, lastName, email, status, gmail, payDate
FROM membership, memberDues
WHERE payDate >= '$year-10-01' AND ID = memberID
ORDER BY lastName, firstName";
$result = mysqli_query($dbCnx, $sql);
while ($row = mysqli_fetch_assoc($result)) {
$gmailArray = array( $row['firstLast'], $row['firstName'], $row['lastName'], "$group", $row['email'] );
fputcsv($output, $gmailArray);}
答案 0 :(得分:0)
我发现了这个问题。我的安全性包括(几年后我没有看过),如果用户有权查看页面,则插入验证行。我认为每隔一段时间检查一下插件和播放代码就很有用了,以帮助解决这些类型的烦恼。