problem displaying pdfs from mysql

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

    problem displaying pdfs from mysql

    Hi I have uploaded a pdf file into my db and am trying to display it
    again here is the code i have used (at the moment it is just displaying
    the binary file's code as text in a html page:

    <?php session_start() ;
    include("connec tion.php");

    $query = "SELECT resource, resource_name FROM tblresources WHERE id =
    '3' ";

    $result = mysql_query($qu ery) or die(mysql_error () );

    $row = mysql_fetch_arr ay($result);
    $content = $row['resource'];

    header("Content-type: application/pdf");

    echo $content;

    ?>

    //am i missing something else to go with header to make it be read as a
    pdf file?

    Please help!

  • Rik

    #2
    Re: problem displaying pdfs from mysql

    monomaniac21 wrote:[color=blue]
    > header("Content-type: application/pdf");[/color]

    add:
    header('Content-Disposition: attachment; filename="somen ame.pdf"');

    should work, BTW directy from


    Grtz,
    --
    Rik Wasmus


    Comment

    • monomaniac21

      #3
      Re: problem displaying pdfs from mysql

      Cheers Rik is that also required for displaying jpgs and stuff? i dont
      remember using it.

      Comment

      • Rik

        #4
        Re: problem displaying pdfs from mysql

        monomaniac21 wrote:[color=blue]
        > Cheers Rik is that also required for displaying jpgs and stuff? i dont
        > remember using it.[/color]

        Not for images, no. Allthough some browsers (I know IE does) display pdf's,
        it's not HTML, it's officially not for a browser to handle. Browsers can
        display HTML and other "simple" files (for instance XML, TXT, all files
        easily made in notepad and the like), and (most) images.

        Other files have to be first downloaded and then displayed with other
        programs. IE uses an external pdf-reader (normally acrobat), but pretends it
        is capable of displaying pdf's by running the program "inline" (for lack of
        a better word, my english is limited). Hence the confusion.

        That's putting it simple. I'm sure there are people on this ng that DO know
        what they are talking about who can correct me, but this explanation has
        sufficed for me so far :-)

        Grtz,
        --
        Rik Wasmus


        Comment

        • Chuck Anderson

          #5
          Re: problem displaying pdfs from mysql

          Rik wrote:
          [color=blue]
          >monomaniac21 wrote:
          >
          >[color=green]
          >>header("Conte nt-type: application/pdf");
          >>
          >>[/color]
          >
          >add:
          >header('Conten t-Disposition: attachment; filename="somen ame.pdf"');
          >
          >should work, BTW directy from
          >http://nl3.php.net/manual/en/function.header.php
          >
          >Grtz,
          >
          >[/color]
          And I've found that you need to use:
          header('Content-Disposition: inline; filename="somen ame.pdf"');
          .... to display it in the browser

          To create a download, save as dialog use:
          header('Content-Disposition: attachment; filename="somen ame.pdf"');

          --
          *************** **************
          Chuck Anderson • Boulder, CO

          The world is my country,
          Science, my religion
          *************** **************

          Comment

          • Rik

            #6
            Re: problem displaying pdfs from mysql

            Chuck Anderson wrote:[color=blue]
            > And I've found that you need to use:
            > header('Content-Disposition: inline; filename="somen ame.pdf"');
            > ... to display it in the browser
            >
            > To create a download, save as dialog use:
            > header('Content-Disposition: attachment; filename="somen ame.pdf"');[/color]

            As I said, some people do know what they're talking about :-)

            Grtz,
            --
            Rik Wasmus


            Comment

            Working...