View PDF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Slaxer13
    New Member
    • Jun 2014
    • 106

    View PDF

    Hi again. In the following code, which is being used to view pdf in browser

    Code:
    <?php
      $file = 'uploads/.pdf';
      $filename = 'yolo.pdf';
      header('Content-type: application/pdf');
      header('Content-Disposition: inline; filename="' . $filename . '"');
      header('Content-Transfer-Encoding: binary');
      header('Accept-Ranges: bytes');
      @readfile($file);
    ?>
    Is it possible to change the line:

    Code:
     $filename = 'yolo.pdf';
    so that the variable gains the value of another variable which will get its value from a table?

    For example if i have this record on a table (which displays all the records in a db):

    id=1;
    name=marley.pdf ;
    type:pdf;
    size:xxx mb;

    If i click on the name of the file i want a variable that will get that name and put it into the code.

    the code would be something like this:

    Code:
     $filename = '$pdfname';
    I hope you understand what i am trying to ask here...
    Peace,
    Slaxer13
  • computerfox
    Contributor
    • Mar 2010
    • 276

    #2
    Try using the same concept you learned in the other thread....
    I don't recommend setting the header like that. Why do you do that?

    Comment

    • Slaxer13
      New Member
      • Jun 2014
      • 106

      #3
      Just some code i found out but i am currently working on it with a friend. I'll try thanks ;)

      Comment

      • Luuk
        Recognized Expert Top Contributor
        • Mar 2012
        • 1043

        #4
        You can put any code you like before the line '$filename = 'yolo.pdf';'

        as long as you make sure no output is sent to the browser,

        because 'headers()' should be send first, or else you get an error: "Warning: Cannot modify header information - headers already sent (output started at script:line)"

        Comment

        • computerfox
          Contributor
          • Mar 2010
          • 276

          #5
          I would suggest letting the HTTP protocol generate a natural header. Less code, less worry, and it looks cleaner. I have never seen headers being built like that in PHP on a real site in 10 years.

          Comment

          Working...