SfondoScrivi flusso binario al browser utilizzando PHP
Cercando di trasmettere un report PDF scritto utilizzando iReport tramite PHP per il browser. Il problema generale è: come scrivi dati binari nel browser usando PHP?
codice di lavoro
header('Cache-Control: no-cache private');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment, filename=climate-report.pdf');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
$path = realpath(".") . "/output.pdf";
$em = java('net.sf.jasperreports.engine.JasperExportManager');
$result = $em->exportReportToPdf($pm);
header('Content-Length: ' . strlen($result));
$fh = fopen($path, 'w');
fwrite($fh, $result);
fclose($fh);
readfile($path);
non funzionante Codice
header('Cache-Control: no-cache private');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment, filename=climate-report.pdf');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
$path = realpath(".") . "/output.pdf";
$em = java('net.sf.jasperreports.engine.JasperExportManager');
$result = $em->exportReportToPdf($pm);
header('Content-Length: ' . strlen($result));
echo $result;
Domanda
Come posso togliere la fase centrale della scrittura al file e scrivere direttamente al browser in modo che il PDF sia non corrotto?
Aggiornamento
PDF file di dimensioni:
- di lavoro: 594778 byte
- non lavoro: 1.059.365 byte
Grazie!
Aggiunge tutte le intestazioni che si ritagliano dal primo lavoro? –
@Casey: le intestazioni sono sempre state le stesse in entrambi i casi. Vedi il problema rivisto. –
Ah, questo è il rapporto sul clima! Nessuna preoccupazione, è normale. Sono sempre * buggy *;) –