페이지에서 사용중인 Wordpress 테마 템플릿 파일이 있습니다. 템플릿은 db에 대해 배열을 쿼리 한 다음 csv 파일에 결과를 출력하려고 시도합니다. 브라우저에 출력되지 않습니다. 여기에 코드입니다 :php : // 결과가 빈 파일로 출력됩니다.
/***
* Output an array to a CSV file
*/
function download_csv_results($results, $name = NULL)
{
if(! $name)
{
$name = md5(uniqid() . microtime(TRUE) . mt_rand()). '.csv';
}
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header("Expires: 0");
$outstream = fopen("php://output", "w");
foreach($results as $result)
{
fputcsv($outstream, $result);
}
fclose($outstream);
}
파일은 예상대로 사용자의 다운로드 디렉토리에 기록하지만, 비어있다. 117 개 요소의 결과가 있는지 확인하기 위해 디버깅했습니다. 위의 루프가 실행 중입니다. 마치 출력 버퍼가 플러시되지 않거나 Wordpress에 의해 지워지는 것입니다.
당신이'ob_'functions으로 시도 적이 있습니까? – Havelock