Welcome Guest, Not a member yet? Register   Sign In
headers and rare characters to output when download binary data (PDF)
#1

[eluser]Unknown[/eluser]
I using FPDF to generate PDF file and using download helper to force download this. The problem is: first click OK the explorer show dialog to save or open file .pdf, second click the browser no know the format the download no have extension and nothing as expected, the third try maybe work maybe no. I try make work for me but i can't. Please help me.

This my code:

Code:
$ruta = "./public/content/tmp_folder/$user/report";
$img1 = "$ruta/detalletrimestre ano mes Alertas.png";
$img2 = "$ruta/detalletrimestre ano mes Notificaciones.png";
//load utilities
$this->load->library ( 'fpdf' );
$this->load->helper ( 'download' );
$pdf = new FPDF ();
//$pdf->Open ();
$pdf->AddPage ();
$pdf->Image ( $img1 );
$pdf->Image ( $img2 );
$pdf->SetFont ( 'Arial', 'B', 16 );
$pdf->Cell ( 40, 10, 'Hello World!' );
$data = $pdf->Output ( "", "S" );
log_message ( 'error', $data );
ob_end_clean ();
if (! headers_sent ()) {
force_download ( "reporte trimestral alertas.pdf", $data );
}

This code is OK, Iam send the binary generate to log and check this when the file in the browser is bad and the log data is OK, and different to the browser file data, watching the bad file can be seen the extra data before PDF begin %PDF-1.3, the data before the mark have all HTTP headers and another binary data.

The bad file have:
Quote:...;HTTP/1.1 200 OK
Date: Mon, 07 Nov 2011 03:53:49 GMT
Server: Apache/2.2.17 (Win32) PHP/5.3.4
X-Powered-By: PHP/5.3.4
Set-Cookie: ci_session=UWABbAFnUjZV...; path=/
Expires: 0
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Disposition: attachment; filename="reporte trimestral alertas.pdf"
Content-Transfer-Encoding: binary
Content-Length: 53962
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: "application/pdf"

%PDF-1.3...

The good file only begin with %PDF-1.3

Iam using:
WampSever 2.1 with
Apache 2.2.17 and
PHP 5.3.4
CodeIgniter 2.0.3

I added the generated files.
Please help me with this, thx




Theme © iAndrew 2016 - Forum software by © MyBB