Opening a specific PDF file from specific folder after keying in the file name











up vote
-1
down vote

favorite












I've been trying to display a particular PDF file in webpage after keying in the file name in the enter page. (The PDF files are stored in a folder in desktop and also the table numbers/filenames are stored in database)



Codes for entering file name page:



<?php

session_start();

// Connect to database
$db = mysqli_connect("localhost", "root", "", "authentication" );

if (isset($_POST["enter_btn"]))
{
//session_start();
$filename = mysqli_real_escape_string($db, $_POST["filename"]);

$filename = $filename;
$sql = "SELECT * FROM tableno WHERE filename='$filename'";
$resultname = mysqli_query($db, $sql);

if ($filename != "" AND mysqli_num_rows($resultname) == 1)
{
$_SESSION['message'] = "Proceeding to Preview for ";
$_SESSION['filename'] = $filename;
header("location: previewfile.php");
}
else
{
// Failed to key in table number
$_SESSION['message'] = "The table number is empty or the table number does not exist. Please enter again.";
}
}

?>


<!DOCTYPE html>
<html>
<head>
<title>Enter Table Number.</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>

<div class="header">
<h1>Welcome</h1>
</div>

<?php
if (isset($_SESSION['message']))
{
echo"<div id='error_msg'>".$_SESSION['message']."</div>";
unset($_SESSION['message']);
}

?>

<form method="post" action="enterfilename.php">
<table>
<tr>
<td>Please enter Table Number:</td>
<td><input type="text" name="filename" class="textInput"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="enter_btn" value="Enter"></td>
</tr>
<tr>
<p>
Exit page. <a href="logout.php">Logout</a>
</p>
</table>
</form>

</body>

</html>


And the codes for my preview page looks like this:



<?php

function showPDF($id){
$query = "SELECT pdf_content FROM #/Users/username/desktop/PDF/" . $id;
$db->setQuery($query);
$pdfContent = $db->loadResult();
header('Content-type: application/pdf');
header("Cache-Control: no-cache");
header("Pragma: no-cache");
header("Content-Disposition: inline;filename='[$filename.pdf]'");
header("Content-length: ".strlen($pdfContent));
die($pdfContent);
}

?>

<!doctype>

<html>
<head>
<style type="text/css">
#myiframe {width:1260px; height:100%;}
</style>
</head>
<body>

<div align="right">
<a href="enterfilename.php">
<button>X</button>
</a>
</div>

<div align="center">
Proceed to checklist?
</div>

<div align="center">
<a href="page2.php">
<button>YES</button>
</a>
<a href="enterfilename.php">
<button>CANCEL</button>
</a>
</div>

<div id="scroller">
<iframe name="myiframe" id="myiframe" src=filename />
</div>

</body>
</html>


But when I run the codes, I can't display any PDF file and instead it's showing the error:




"Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.



If you think this is a server error, please contact the webmaster.



Error 404"




Please advise if there's any mistake I can work on. Thank you.










share|improve this question









New contributor




sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    -1
    down vote

    favorite












    I've been trying to display a particular PDF file in webpage after keying in the file name in the enter page. (The PDF files are stored in a folder in desktop and also the table numbers/filenames are stored in database)



    Codes for entering file name page:



    <?php

    session_start();

    // Connect to database
    $db = mysqli_connect("localhost", "root", "", "authentication" );

    if (isset($_POST["enter_btn"]))
    {
    //session_start();
    $filename = mysqli_real_escape_string($db, $_POST["filename"]);

    $filename = $filename;
    $sql = "SELECT * FROM tableno WHERE filename='$filename'";
    $resultname = mysqli_query($db, $sql);

    if ($filename != "" AND mysqli_num_rows($resultname) == 1)
    {
    $_SESSION['message'] = "Proceeding to Preview for ";
    $_SESSION['filename'] = $filename;
    header("location: previewfile.php");
    }
    else
    {
    // Failed to key in table number
    $_SESSION['message'] = "The table number is empty or the table number does not exist. Please enter again.";
    }
    }

    ?>


    <!DOCTYPE html>
    <html>
    <head>
    <title>Enter Table Number.</title>
    <link rel="stylesheet" type="text/css" href="style.css">
    </head>

    <body>

    <div class="header">
    <h1>Welcome</h1>
    </div>

    <?php
    if (isset($_SESSION['message']))
    {
    echo"<div id='error_msg'>".$_SESSION['message']."</div>";
    unset($_SESSION['message']);
    }

    ?>

    <form method="post" action="enterfilename.php">
    <table>
    <tr>
    <td>Please enter Table Number:</td>
    <td><input type="text" name="filename" class="textInput"></td>
    </tr>
    <tr>
    <td></td>
    <td><input type="submit" name="enter_btn" value="Enter"></td>
    </tr>
    <tr>
    <p>
    Exit page. <a href="logout.php">Logout</a>
    </p>
    </table>
    </form>

    </body>

    </html>


    And the codes for my preview page looks like this:



    <?php

    function showPDF($id){
    $query = "SELECT pdf_content FROM #/Users/username/desktop/PDF/" . $id;
    $db->setQuery($query);
    $pdfContent = $db->loadResult();
    header('Content-type: application/pdf');
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
    header("Content-Disposition: inline;filename='[$filename.pdf]'");
    header("Content-length: ".strlen($pdfContent));
    die($pdfContent);
    }

    ?>

    <!doctype>

    <html>
    <head>
    <style type="text/css">
    #myiframe {width:1260px; height:100%;}
    </style>
    </head>
    <body>

    <div align="right">
    <a href="enterfilename.php">
    <button>X</button>
    </a>
    </div>

    <div align="center">
    Proceed to checklist?
    </div>

    <div align="center">
    <a href="page2.php">
    <button>YES</button>
    </a>
    <a href="enterfilename.php">
    <button>CANCEL</button>
    </a>
    </div>

    <div id="scroller">
    <iframe name="myiframe" id="myiframe" src=filename />
    </div>

    </body>
    </html>


    But when I run the codes, I can't display any PDF file and instead it's showing the error:




    "Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.



    If you think this is a server error, please contact the webmaster.



    Error 404"




    Please advise if there's any mistake I can work on. Thank you.










    share|improve this question









    New contributor




    sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      I've been trying to display a particular PDF file in webpage after keying in the file name in the enter page. (The PDF files are stored in a folder in desktop and also the table numbers/filenames are stored in database)



      Codes for entering file name page:



      <?php

      session_start();

      // Connect to database
      $db = mysqli_connect("localhost", "root", "", "authentication" );

      if (isset($_POST["enter_btn"]))
      {
      //session_start();
      $filename = mysqli_real_escape_string($db, $_POST["filename"]);

      $filename = $filename;
      $sql = "SELECT * FROM tableno WHERE filename='$filename'";
      $resultname = mysqli_query($db, $sql);

      if ($filename != "" AND mysqli_num_rows($resultname) == 1)
      {
      $_SESSION['message'] = "Proceeding to Preview for ";
      $_SESSION['filename'] = $filename;
      header("location: previewfile.php");
      }
      else
      {
      // Failed to key in table number
      $_SESSION['message'] = "The table number is empty or the table number does not exist. Please enter again.";
      }
      }

      ?>


      <!DOCTYPE html>
      <html>
      <head>
      <title>Enter Table Number.</title>
      <link rel="stylesheet" type="text/css" href="style.css">
      </head>

      <body>

      <div class="header">
      <h1>Welcome</h1>
      </div>

      <?php
      if (isset($_SESSION['message']))
      {
      echo"<div id='error_msg'>".$_SESSION['message']."</div>";
      unset($_SESSION['message']);
      }

      ?>

      <form method="post" action="enterfilename.php">
      <table>
      <tr>
      <td>Please enter Table Number:</td>
      <td><input type="text" name="filename" class="textInput"></td>
      </tr>
      <tr>
      <td></td>
      <td><input type="submit" name="enter_btn" value="Enter"></td>
      </tr>
      <tr>
      <p>
      Exit page. <a href="logout.php">Logout</a>
      </p>
      </table>
      </form>

      </body>

      </html>


      And the codes for my preview page looks like this:



      <?php

      function showPDF($id){
      $query = "SELECT pdf_content FROM #/Users/username/desktop/PDF/" . $id;
      $db->setQuery($query);
      $pdfContent = $db->loadResult();
      header('Content-type: application/pdf');
      header("Cache-Control: no-cache");
      header("Pragma: no-cache");
      header("Content-Disposition: inline;filename='[$filename.pdf]'");
      header("Content-length: ".strlen($pdfContent));
      die($pdfContent);
      }

      ?>

      <!doctype>

      <html>
      <head>
      <style type="text/css">
      #myiframe {width:1260px; height:100%;}
      </style>
      </head>
      <body>

      <div align="right">
      <a href="enterfilename.php">
      <button>X</button>
      </a>
      </div>

      <div align="center">
      Proceed to checklist?
      </div>

      <div align="center">
      <a href="page2.php">
      <button>YES</button>
      </a>
      <a href="enterfilename.php">
      <button>CANCEL</button>
      </a>
      </div>

      <div id="scroller">
      <iframe name="myiframe" id="myiframe" src=filename />
      </div>

      </body>
      </html>


      But when I run the codes, I can't display any PDF file and instead it's showing the error:




      "Object not found!
      The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.



      If you think this is a server error, please contact the webmaster.



      Error 404"




      Please advise if there's any mistake I can work on. Thank you.










      share|improve this question









      New contributor




      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I've been trying to display a particular PDF file in webpage after keying in the file name in the enter page. (The PDF files are stored in a folder in desktop and also the table numbers/filenames are stored in database)



      Codes for entering file name page:



      <?php

      session_start();

      // Connect to database
      $db = mysqli_connect("localhost", "root", "", "authentication" );

      if (isset($_POST["enter_btn"]))
      {
      //session_start();
      $filename = mysqli_real_escape_string($db, $_POST["filename"]);

      $filename = $filename;
      $sql = "SELECT * FROM tableno WHERE filename='$filename'";
      $resultname = mysqli_query($db, $sql);

      if ($filename != "" AND mysqli_num_rows($resultname) == 1)
      {
      $_SESSION['message'] = "Proceeding to Preview for ";
      $_SESSION['filename'] = $filename;
      header("location: previewfile.php");
      }
      else
      {
      // Failed to key in table number
      $_SESSION['message'] = "The table number is empty or the table number does not exist. Please enter again.";
      }
      }

      ?>


      <!DOCTYPE html>
      <html>
      <head>
      <title>Enter Table Number.</title>
      <link rel="stylesheet" type="text/css" href="style.css">
      </head>

      <body>

      <div class="header">
      <h1>Welcome</h1>
      </div>

      <?php
      if (isset($_SESSION['message']))
      {
      echo"<div id='error_msg'>".$_SESSION['message']."</div>";
      unset($_SESSION['message']);
      }

      ?>

      <form method="post" action="enterfilename.php">
      <table>
      <tr>
      <td>Please enter Table Number:</td>
      <td><input type="text" name="filename" class="textInput"></td>
      </tr>
      <tr>
      <td></td>
      <td><input type="submit" name="enter_btn" value="Enter"></td>
      </tr>
      <tr>
      <p>
      Exit page. <a href="logout.php">Logout</a>
      </p>
      </table>
      </form>

      </body>

      </html>


      And the codes for my preview page looks like this:



      <?php

      function showPDF($id){
      $query = "SELECT pdf_content FROM #/Users/username/desktop/PDF/" . $id;
      $db->setQuery($query);
      $pdfContent = $db->loadResult();
      header('Content-type: application/pdf');
      header("Cache-Control: no-cache");
      header("Pragma: no-cache");
      header("Content-Disposition: inline;filename='[$filename.pdf]'");
      header("Content-length: ".strlen($pdfContent));
      die($pdfContent);
      }

      ?>

      <!doctype>

      <html>
      <head>
      <style type="text/css">
      #myiframe {width:1260px; height:100%;}
      </style>
      </head>
      <body>

      <div align="right">
      <a href="enterfilename.php">
      <button>X</button>
      </a>
      </div>

      <div align="center">
      Proceed to checklist?
      </div>

      <div align="center">
      <a href="page2.php">
      <button>YES</button>
      </a>
      <a href="enterfilename.php">
      <button>CANCEL</button>
      </a>
      </div>

      <div id="scroller">
      <iframe name="myiframe" id="myiframe" src=filename />
      </div>

      </body>
      </html>


      But when I run the codes, I can't display any PDF file and instead it's showing the error:




      "Object not found!
      The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.



      If you think this is a server error, please contact the webmaster.



      Error 404"




      Please advise if there's any mistake I can work on. Thank you.







      php html






      share|improve this question









      New contributor




      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 5 at 4:22









      nextstep

      8863820




      8863820






      New contributor




      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 5 at 2:44









      sandnspace

      1




      1




      New contributor




      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      sandnspace is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          sandnspace is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147655%2fopening-a-specific-pdf-file-from-specific-folder-after-keying-in-the-file-name%23new-answer', 'question_page');
          }
          );

          Post as a guest





































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          sandnspace is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          sandnspace is a new contributor. Be nice, and check out our Code of Conduct.













          sandnspace is a new contributor. Be nice, and check out our Code of Conduct.












          sandnspace is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147655%2fopening-a-specific-pdf-file-from-specific-folder-after-keying-in-the-file-name%23new-answer', 'question_page');
          }
          );

          Post as a guest




















































































          這個網誌中的熱門文章

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud

          Zucchini