I have a MySQL db that stores PDFs, i want to be able to use a SQL statement to single out a PDF, say the one with the latest date and embed it with in webpage.

I dont want to prompt for download or open it on a new page as most of my google searches have come up with, i want it to show within the page.

Hope someone can help??????

    The sure-fire way is to use an iFrame. Here's an example from the manual for the iFrame page you want to embed:

    // We'll be outputting a PDF
    header('Content-type: application/pdf');
    
    // It will be called downloaded.pdf
    header('Content-Disposition: attachment; filename="downloaded.pdf"');
    
    // The PDF source is in original.pdf
    readfile('original.pdf');

    I also found this, but haven't tried it and don't know if there are any quirks:

    <object data="data/test.pdf" type="application/pdf" width="300" height="200">
      alt : <a href="data/test.pdf">test.pdf</a>
    </object>

      Thanks for your reply, this is kind of what i have up to now

      <?php

      include("conn_inc_reg.php");

      $query = "select * from mktreportsupload where id='35'";
      $result = mysql_query($query) or die(mysql_error() );

      $row = mysql_fetch_array($result);

      $content = $row[content]; \content is the blob data

      header("Content-type: application/pdf");
      header('Content-Disposition: attachment; filename="downloaded.pdf"');
      readfile('original.pdf');

      print $content;

      ?>

      Are the names for downloaded.pdf and original.pdf relevant to anything??

      How would you change the above code to get it to work? Sorry most things relating to PHP/MySQL i can get my head round but this one has baffled me!

        Thanks for your replay, this is what i have up to now:

        <?php

        include("conn_inc_reg.php");

        $query = "select * from mktreportsupload where id='35'";
        $result = mysql_query($query) or die(mysql_error() );

        $row = mysql_fetch_array($result);

        $content = $row[content];

        header("Content-type: application/pdf");
        header('Content-Disposition: attachment; filename="downloaded.pdf"');
        readfile('original.pdf');

        print $content;

        ?>

        How would you change this to get it to work??

        Sorry i normally can work out most issues with PHP/MySQL but this has got me baffled!

          Sorry, I meant to give you a very general answer, not a specific one. Try it with just the one header:

          include("conn_inc_reg.php");
          
          $query = "select * from mktreportsupload where id='35'";
          $result = mysql_query($query) or die(mysql_error() );
          
          $row = mysql_fetch_array($result);
          
          $content = $row[content]; \\content is the blob data
          
          header("Content-type: application/pdf");
          
          print $content;

          Remember, this is in an iFrame. Again, I haven't tried the <embed> tag with a PDF, but I assume you'd just leave out the iframe/header part and add the <embed> tag instead.

            Looks like it works!!

            Using the iframes i think was the key as the embed tags seems to have issues displaying, i set the code in a seperate php file then referred to it from the iframe and hey presto!!

            Thanks for your help!

              Write a Reply...