php fputscv没有创建csv文件而是在同一页面上显示输出

时间:2015-05-20 19:55:36

标签: php csv fputcsv

在我的本地机器上工作正常。但是在服务器上,它会在同一页面上打印输出,而不是创建CSV文件。任何人都可以帮忙

// output headers so that the file is downloaded rather than displayed

header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=memberList.csv');

ob_end_clean();

// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

// output the column headings
fputcsv($output, array('First Name', 'Last Nameenter code here', 'Street Name', 'City', 'State', 'Zip Code'));

// fetch the data
$csvQry  = "SELECT * from tabel where num=1";

if ($_POST['stateList']!='all'){
    $csvQry  = "SELECT * from table";
}

$csvRows = mysqli_query($db,$csvQry);

// loop over the rows, outputting them
while ($csvRow = mysqli_fetch_assoc($csvRows)) {
   fputcsv($output, $csvRow);
}

fclose($output);

0 个答案:

没有答案