i would like to be able to upload a pdf to a database then later be able to download the book and view it. i want the names of the books to appear as links which when clicked will open the book. the uploading is being done but the downloading is giving me problems. this is the upload php file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Upload2.php</title>
</head>
<body>
<?php
if(isset($_POST['Upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
//include 'library/opendb.php';
//include 'library/config.php';
$dbcnx = @mysql_connect("localhost","root","");
if(!$dbcnx)
{
die('Could not connect to database:'.mysql_error());
}
$tableLink = @mysql_select_db('book3', $dbcnx);
if(!$tableLink)
{
die('Could not connect:'.mysql_error());
}
$query = "INSERT INTO books (name, size, type, content)". "VALUES ('$fileName','$fileSize','$fileType','$content')";
mysql_query($query) or die('Error sql failed');
echo "File $fileName uploaded";
}
?>
</body>
</html>
and this is the download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>download 1</title>
</head>
<body>
<?php
$dbcnx = mysql_connect("localhost","root","")
or die('Unable to connect to database');
mysql_select_db(book3)
or die('unable to connect');
$query = "SELECT id,name FROM books LIMIT 0,30";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) > 0)
{
while($row = mysql_fetch_object($result))
{
?>
<!--echo "<a href=\"download1.php?id=$id\">$name</a><br/>";-->
<a href="download1.php?id= <?php echo $row->id; ?>"><?php echo $row->name; ?></a><br /><?php
}
}
else
{
echo "data is empty";
}
mysql_close($dbcnx);
?>
<?php
if(!isset($_GET['id']) || trim($_GET['id'] == ''))
{
die('Missing record ID');
}
else
{
$id = $_GET['id'];
//echo $id;
$dbcnx = mysql_connect("localhost","root","")
or die('Unable to connect to database');
mysql_select_db(book3)
or die('unable to connect');
$query = "SELECT name, type,size,content FROM books WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_object($result);
if($row)
{
?>
<?php echo nl2br($row->content); ?>
<?php
}
}
?>
</body>
</html>
at present what i get is that the browser tries to open the document but appears as though its encrypted or corrupt. i get know errors.
hope i am clear as to what i want to do