You are here: Re: [PHP] Problems with header() « PHP « IT news, forums, messages
Re: [PHP] Problems with header()

Posted by Tom Rogers on 06/18/05 07:38

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация