Serving PDF Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kubaton Lover

    Serving PDF Problem

    I'm still having a problem with the following code, but I can better
    describe the symptoms now.

    Code:

    <?php
    $uri = getenv('REQUEST _URI');
    $pieces = explode('/',$uri);
    $file = $pieces[count($pieces)-1];

    header("Content-type: application/pdf");
    header("Content-Disposition: attachment; filename=".$fil e);
    readfile('/home/america2/pdfs/'.$file);
    ?>


    The code appears to work perfectly in NN7, but in IE6 it only works when the
    user chooses to "Save" the file to the hard drive. If the user chooses to
    open the file, Adobe Reader launches, but before a PDF is rendered, the
    following error is displayed.

    "There was an error opening this document. The file does not exist."

    Any suggestions?


  • Kubaton Lover

    #2
    Re: Serving PDF Problem

    "Kubaton Lover" <nospam@goaways pam.com> wrote in message
    news:vr1ri480j4 ap26@corp.super news.com...[color=blue]
    > I'm still having a problem with the following code, but I can better
    > describe the symptoms now.
    >
    > Code:
    >
    > <?php
    > $uri = getenv('REQUEST _URI');
    > $pieces = explode('/',$uri);
    > $file = $pieces[count($pieces)-1];
    >
    > header("Content-type: application/pdf");
    > header("Content-Disposition: attachment; filename=".$fil e);
    > readfile('/home/america2/pdfs/'.$file);
    > ?>
    >
    >
    > The code appears to work perfectly in NN7, but in IE6 it only works when[/color]
    the[color=blue]
    > user chooses to "Save" the file to the hard drive. If the user chooses to
    > open the file, Adobe Reader launches, but before a PDF is rendered, the
    > following error is displayed.
    >
    > "There was an error opening this document. The file does not exist."
    >
    > Any suggestions?
    >[/color]

    In case anyone else has this problem... the problem is the following line:
    header("Content-Disposition: attachment; filename=".$fil e);

    In a previous thread, "R. Rajesh Jeba Anbiah" suggested a website
    (http://in2.php.net/header ). That website suggested that I add that line
    to fix a "bug" with IE6. I'd have to go back and re-read it to see what it
    was trying to fix, but it appears to have caused more problems for me than
    corrected.

    All seems to be working great now.


    Comment

    • R. Rajesh Jeba Anbiah

      #3
      Re: Serving PDF Problem

      "Kubaton Lover" <nospam@goaways pam.com> wrote in message news:<vr1sqriup j6g30@corp.supe rnews.com>...[color=blue]
      > "Kubaton Lover" <nospam@goaways pam.com> wrote in message
      > news:vr1ri480j4 ap26@corp.super news.com...[/color]
      <snip>
      [color=blue]
      > In case anyone else has this problem... the problem is the following line:
      > header("Content-Disposition: attachment; filename=".$fil e);
      >
      > In a previous thread, "R. Rajesh Jeba Anbiah" suggested a website
      > (http://in2.php.net/header ). That website suggested that I add that line
      > to fix a "bug" with IE6. I'd have to go back and re-read it to see what it
      > was trying to fix, but it appears to have caused more problems for me than
      > corrected.[/color]

      Did you actually read the usernotes there? Is the following note
      caused you the problem actually?

      <--------------------------------->
      15-Oct-2003 12:27
      Some browsers out there on the Internet act funny, especially with
      Internet Explorer (IE), so this script will help. This is ony an
      example for displaying the PDF. You can REM out the code and change
      it to make it be a downloadable file instead.

      --snip--
      <?
      $filename=$_REQ UEST['PDF_FileName'];
      $filepath=$_REQ UEST['PDF_FilePath'];

      $filesize=files ize($filepath);

      header("Pragma: public");
      header("Expires : 0"); // set expiration time
      header("Cache-Control: must-revalidate, post-check=0,
      pre-check=0");

      header("Content-Type: application/pdf");
      header("Content-Length: ".$filesize );
      header("Content-Disposition: inline; filename=$filen ame");
      header("Content-Transfer-Encoding: binary");

      //Can't use readfile() due to poor controlling of the file
      download.
      //(IE have this problems)...
      //readfile($filep ath);

      //use fopen() instead of readfile...
      $fp = fopen($filepath , 'rb');
      $pdf_buffer = fread($fp, $filesize);
      fclose ($fp);

      //sleep(1);

      print $pdf_buffer;

      //Required, to keep IE from running into problems
      //when opening the file while downloading or downloading...
      //(IE been acting strange lately...)
      exit();
      ?>
      --snip--
      <--------------------------------->

      ---
      "We live to die; we die to live"
      Email: rrjanbiah-at-Y!com

      Comment

      Working...