I upload the PDF Files and save it into the MySQL in a BLOB field.
I managed to create download links for it.
But I need to open it in the browser, how can this be done ?
This code is to download PDF's
$result = mysql_query($query);
if($result)
{
// Make sure the result is valid
if(mysql_num_rows($result) == 1)
{
// Get the row
$row = mysql_fetch_assoc($result);
// Print headers
header("Content-Type:".$row['mime'] );
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
// Print data
echo $row['data'];
}
This code is to Upload PDF in BLOB's
if($_FILES['uploaded_file']['error'] == 0)
{
// Connect to the database
$dbLink = mysql_connect("localhost", "root", "");
mysql_select_db("testdatabase", $dbLink) or die (mysql_error());
// Gather all required data
$name = mysql_real_escape_string($_FILES['uploaded_file']['name']);
$mime = mysql_real_escape_string($_FILES['uploaded_file']['type']);
$data = mysql_real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name']));
$size = intval($_FILES['uploaded_file']['size']);
// Create the SQL query
$query = " INSERT INTO files (name, mime, size, data, created)
VALUES ('$name', '$mime', $size,'$data', NOW())";
// Execute the query
$result = mysql_query($query);