0
我有一些问题需要从读取文件的数组中创建一个csv文件。使用php创建的Csv也包含页面代码
if(isset($_POST['expcsvmail'])){
$filemail= '../config/mail.txt';
$mail=file($filemail, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$fp = fopen('exported_mails.csv', 'w+');
foreach($mail as $df)
fputcsv($fp, array($df));
fclose($fp);
header("Content-Type: text/csv");
header("Cache-Control: no-store, no-cache");
header("Content-Description: List of Emails");
header("Content-Disposition: attachment;filename=exported_mails.csv");
header("Content-Transfer-Encoding: binary");
readfile('exported_mails.csv');
unlink('exported_mails.csv');
}
这是我怎么称呼它:
<form action="function.php" target="hidden_upload" class='formcor' method='post'>
<input type="submit" id='expcsvmail' name='expcsvmail' value="Export Emails to CSV" class='sendval'/>
现在我有两个问题:如果我的页面的刷新后调用它(基本上是这段代码在调用页面)csv已经进入数组后,页面的所有代码
否则,如果我用外部文件调用它,我在文件结尾有一个换行符(应该不会在那里)
有人可以帮忙吗? 我?谢谢