我有php
函数:
function get_partij_download($dbmi, $partij) {
set_time_limit(0);
$stmt = $dbmi->prepare("CALL spStartPartijDownload(?)");
$stmt->bind_param('i', $partij);
$stmt->execute();
$result = $stmt->get_result();
$headers = array('zorgverlener', 'zorgverlener_type', 'jaar','dc_code', 'dc_oms', 'tt_oms', 'zp_code', 'zp_oms', 'zpg_oms',
'source1', 'source2', 'source3', 'source4');
$fp = fopen('php://output', 'w');
if ($fp && $result) {
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export_tarieven.csv"');
fputcsv($fp, $headers, ";");
while($row = $result->fetch_assoc()) {
fputcsv($fp, $row, ";");
}
}
$stmt->close();
return $fp;
}
这很有用,可以根据需要进行csv
下载。 csv
也有内容。现在我想首先压缩csv
,然后下载zip。我将功能更改为:
function get_partij_download($dbmi, $partij) {
set_time_limit(0);
$stmt = $dbmi->prepare("CALL spStartPartijDownload(?)");
$stmt->bind_param('i', $partij);
$stmt->execute();
$result = $stmt->get_result();
$headers = array('zorgverlener', 'zorgverlener_type', 'jaar','dc_code', 'dc_oms', 'tt_oms', 'zp_code', 'zp_oms', 'zpg_oms',
'source1', 'source2', 'source3', 'source4');
//$fp = fopen('php://output', 'w');
$fp = fopen('php://temp/maxmemory:1048576', 'w');
if ($fp && $result) {
// create your zip file
$zipname = 'export_tarvieven_contractpartij.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
fputcsv($fp, $headers, ";");
while($row = $result->fetch_assoc()) {
fputcsv($fp, $row, ";");
}
$zip->addFromString('export_tarieven.csv', stream_get_contents($fp) );
fclose($fp);
$zip->close();
}
$stmt->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
unlink($zipname);
}
现在已经下载了zip,但zip(export_tarieven_contractpartij.csv
)中的文件没有内容,换句话说:csv
为空。有什么想法吗?
此致