Re: Problems with header()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Saturday, June 18, 2005, 7:55:10 AM, you wrote:
MM> I have to send a PDF file after a submit on a form. The PDF is well created,
MM> and I'm sending it to the client with this:

MM> $fpdfName = "/tmp/" . session_id() . ".pdf";

MM> // Vamos a mandar el PDF
MM> header('Content-type: application/pdf');
MM> // El archivo se va a llamar libreDeuda.pdf
MM> header('Content-Disposition: attachment; filename="libreDeuda' . 
MM>    '.pdf"');
MM> // El PDF fuente va a ser $ftexName.
MM> readfile($fpdfName);

MM> The problem is that the PDF file that is sent is corrupted for acroread (xpdf
MM> reads it like a charme), because, after the end of file (%%EOF) of PDF there
MM> is an HTML page add to the file.

MM> Is there anyway I can solve this? Is the sintaxis I used for sending a file
MM> correct?

Here is a script I use to send pdfs which also handles caching
information. It may just be you are missing the content-length header?

<?php
$cache_time = false;
$requested_time = false;

$filename = "/tmp/" . session_id() . ".pdf";
$len = filesize($filename);

$mtime = filemtime($filename);
$cache_time = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
header('Last-Modified: '.$cache_time);

$rt = (empty($_SERVER['HTTP_IF_MODIFIED_SINCE']))? false : $_SERVER['HTTP_IF_MODIFIED_SINCE'];
if($rt) $requested_time = strtotime($rt);

if($requested_time && $cache_time){
        if($requested_time == $cache_time){
                Header($_SERVER['SERVER_PROTOCOL'].' 304 Not Modified');
                exit;
        }
}
header("Accept-Ranges: bytes");
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: application/pdf");
header("Content-Length: $len");
readfile($filename);

-- 
regards,
Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux