I have a uload script that saves PDFs to the DB, and i have another page, where I want to read the PDF file, but the latter is not really happening..
AM I DEFINING MY PDF_DIR CORRECT:
define('PDFS_DIR', $_SERVER['DOCUMENT_ROOT'] .'includes/pdfs');
This is the read_pdf.php file:
<?php require_once("includes/config.php"); ?>
<?php require(MYSQL); ?>
<?php $valid =''; ?>
<?php
if(isset($_GET['id'])&&(strlen($_GET['id'])==40)&&(substr($_GET['id'],0,1)!='.')){
$file = 'PDFS_DIR'.$_GET['id'];
//echo $file; // Does echo out the id of the file!
if(file_exists($file)&&(is_file($file))){
$query = 'SELECT title, description, file_name, FROM pdfs WHERE tmp_name="'.mysqli_real_escape_string($connection, $_GET['id']).'"';
$result = mysqli_query($connection, $query);
if($mysqli_num_rows($result) == 1){//OK!
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$valid = true;
$fs = filesize($file);
header("Content-Length:$fs\n");
header('Content-type:application/pdf');
header('Content-Disposition: inline;filename="'.$row['file_name'].'"');
readfile($file);
//exit();
}
}
}
?>
I get an error = undefined variable $row, which is marked in bold just down here.
Further down the page try to echo out the file:
<?php
echo "<div>{[B]$row[/B]['description']}</div>"; // HERE I GET AN ERROR - UNDEFINED VARIABLE!??
if(!$valid){// = Error
echo'<h4>Der er sket en fejl og PDF-filen kunne ikke vises.
Vi beklager ulejligheden, og vil løse problemet hurtigst muligt, da vores Administrator er blevet automatisk informeret!</h4>';
}
?>
Guys and girls:
How can I read the PDF files I have uploaded to my database?????????????
Klemme