3

Most peculiar problem with following code. It returns a pdf report to the browser.

function cart_aspdf() {
    trace('cart_aspdf_in');
    $file = 'order_WS000250.pdf';
    header('Content-type: application/pdf');
    header('Content-Disposition: inline; filename="' . $file . '"');
    $file =  APPPATH.'pdfcache/'.$file;
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($file));
    header('Accept-Ranges: bytes');
    trace('cart_aspdf_readfile');
    @readfile($file);
    trace('cart_aspdf_out');
}

The trace output in opera,firefox,ie,safari is as you would expect:

  1. cart_aspdf_in
  2. cart_aspdf_readfile
  3. cart_aspdf_out

BUT the trace for chrome shows the following which seems to indicate that the function is being called at least twice if not three times. Why should this be so?

  1. cart_aspdf_in
  2. cart_aspdf_readfile
  3. cart_aspdf_out
  4. cart_aspdf_in
  5. cart_aspdf_readfile
  6. cart_aspdf_in
  7. cart_aspdf_readfile
  8. cart_aspdf_out

The problem does not occur if I omit the content-type line but then chrome shows the raw pdf data which is no use

Andrey Volk
  • 3,513
  • 2
  • 17
  • 29

1 Answers1

0

I ran into the same problem.

header('Content-Disposition: inline;');

For whatever reason, when the content-disposition is inline it calls the page twice.

This was giving me problems trying to use the referrer because the second call does not pass referrer data.

using

header('Content-Disposition: attachment;');

only runs once, but will not display inside the browsers PDF viewer. It will instead download the file.

I think this needs to be posted on chrome's bugtracker. This is quite annoying and for streaming files a bandwidth waste.

Impossibear
  • 195
  • 5