0

该脚本成功地将 pdf 生成到文件夹 tmp/....

但是浏览器的 ZIP 输出是空的,我不知道我做错了什么。

$file = tempnam("tmp", "zip"); 

$zip = new ZipArchive(); 

// Zip will open and overwrite the file, rather than try to read it. 
$zip->open($file, ZipArchive::OVERWRITE);
foreach( explode( ',', $_POST["ids"]) as $Client_ID)
{
  $sql_qry="select *
            from   ca_client_statement
            where  client_id='".$Client_ID."' and trading_period_month like '".$TP_Month."'";
  $sql_err_no=sql_select($sql_qry,$sql_res,$sql_row_count,$sql_err,$sql_uerr);

  //echo $sql_qry;
  //echo '<br/>';
  $row = mysql_fetch_assoc($sql_res);
  $file_content = $row['pdf_statement'];
  $file_name = 'tmp/'.$Client_ID.'statement.pdf';
  $pdf=file_put_contents($file_name, $file_content);
  $zip->addFile($pdf);
} 

$zip->close(); 

// Stream the file to the client 
header("Content-Type: application/zip"); 
header("Content-Length: " . filesize($file)); 
header("Content-Disposition: attachment; filename=\"a_zip_file.zip\""); 
readfile($file); 

unlink($file); 
4

1 回答 1

2

file_put_contents()返回写入的字节数,而不是文件名。尝试将其后的行更改为:

$zip->addFile($file_name);
于 2012-06-28T17:35:41.257 回答