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.
php html
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.
add a comment |
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.
php html
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.
add a comment |
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.
php html
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
php html
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.
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.
add a comment |
add a comment |
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password