IE (HTTPS): generating pdf from php file doesn't work

后端 未结 6 1501

Here is my issue. I am trying to call a page: foo.php?docID=bar and return a PDF to the screen which is stored as a BLOB in the DB.

Here is the portion of my code w

相关标签:
6条回答
  • 2020-12-30 08:52

    Try this:

     header("Content-Type: application/pdf");
     header("Content-Disposition: inline; filename=foo.pdf");
     header("Accept-Ranges: bytes");
     header("Content-Length: $len");
     header("Expires: 0");
     header("Cache-Control: private");
    

    Also, if you are using sessions, you can try setting

    session_cache_limiter("none");
    

    or

    session_cache_limiter("private");
    
    0 讨论(0)
  • 2020-12-30 08:54

    This was the only header I needed to change:

    header("Pragma: public");
    
    0 讨论(0)
  • 2020-12-30 08:55
    if ( USR_BROWSER_AGENT == 'IE' ) {
        header( 'Content-Disposition: inline; filename="' . $name . '"');
        header( 'Expires: 0' );
        header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
        header( 'Pragma: public' );
    } else {
        header( 'Content-Disposition: attachment; filename="' . $name . '"' );
        header( 'Expires: 0' );
        header( 'Pragma: no-cache' );
    }
    
    0 讨论(0)
  • 2020-12-30 09:07

    I figured out what the issue was. It's an IE bug dealing with IE, HTTPS and addons. (See here)

    It was a caching issue. When I set:

      header("Cache-Control:  max-age=1");
      header("Pragma: public");
    

    (see here), the PDF was in cache long enough for the adobe reader add-on to grab it.

    0 讨论(0)
  • 2020-12-30 09:10

    I had this issue too, i used the following which seems to work fine

    header("Content-type: application/pdf");
    header("Content-Length: $length");
    header("Content-Disposition: inline; filename='$filename'");
    
    0 讨论(0)
  • 2020-12-30 09:10

    I think you need to add more headers.

    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment; filename=THEFILENAME.pdf;");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: " . strlen($results[1]));
    
    0 讨论(0)
提交回复
热议问题