Page 1 of 1

Firefox does not display PDFs

Posted: Sun Jul 01, 2007 7:35 am
by yacahuma
patrikG | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am trying to figure out why firefox 2 does not like this. Explorer has no problem displaying the pdf
Any ideas??????????????

[syntax="php"]<?php
$filename='test.pdf';
$len = filesize($filename);
header('Content-type: application/pdf');
header('Content-Length: $len');
header('Content-Disposition: inline;    filename="test.pdf"');
readfile($filename);
?>

patrikG | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Jul 01, 2007 8:11 am
by superdezign
Probably has to do with:

Code: Select all

header('Content-Length: $len');
IE tries to "fix" your code, so that may be why it works. What you are doing is literally sending the string "$len" as the size, which is an invalid value. Try this:

Code: Select all

header('Content-Length: ' . $len);

Posted: Sun Jul 01, 2007 8:13 am
by miro_igov
And what does firefox? If you see the page source what is displayed there?

Posted: Sun Jul 01, 2007 8:28 am
by patrikG

code fix , still the same

Posted: Sun Jul 01, 2007 9:26 am
by yacahuma
My bad.

Code: Select all

header('Content-Length: ' . $len);
Still the same thing. Firefox does nothing. Since there is nothing I cannot do a page view source.


Can anyone try this at home. Just use any pdf. I want to know if is my firefox (I doubt it).

Posted: Sun Jul 01, 2007 9:29 am
by miro_igov
Why you cant do page source? use Ctrl+U. If the source view is empty then the reason is in your test.pdf. Do readfile('test.pdf'); without to set headers.

Posted: Sun Jul 01, 2007 9:32 am
by patrikG
Look into using ocet-stream as content type as suggest in the link I posted above.

Thank for the link BUT need mod

Posted: Sun Jul 01, 2007 9:38 am
by yacahuma
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Patrick thank a lot for the link.  The code did not worked for me. I actually combine my code with that one
take a look.  Using the code at the site I got an invalif pdf.

This now works

Code: Select all

$filename = "test.pdf";
$content_len = filesize($filename);

$output_file = $filename;

@ob_end_clean();
@ini_set('zlib.output_compression', 'Off');
header('Pragma: public');

header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate'); // HTTP/1.1
header('Cache-Control: pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
header('Content-Transfer-Encoding: none');
header('Content-Type: application/octetstream; name="' . $output_file . '"'); //This should work for IE & Opera
header('Content-Type: application/octet-stream; name="' . $output_file . '"'); //This should work for the rest
header('Content-Disposition: inline; filename="' . $output_file . '"');
header("Content-length: $content_len");
readfile($filename);
exit();
I love php!!!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

just for info

Posted: Sun Jul 01, 2007 9:43 am
by yacahuma
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I replaced

Code: Select all

$filename = "test.pdf";
$f = fopen($filename, "rb");
$content_len = (int) filesize($f, $filename);
$content_file = fread($f, $content_len);
fclose($f); 
...
echo $content_file;
with

Code: Select all

$filename = "test.pdf";
$content_len = filesize($filename);
...
readfile($filename);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]