Hi,
After uploading a pdf from a form, i am trying to read the file.
It is saved in DB, and i try to get the chosen PDF via a link that holds a unique value from the DB, so the chosen PDF can be identified, and displayed.
BUT, I only get the eror message from the bottom of the script, so something goes wrong, as I cant read the file, or something in my code is wrong, and doesnt get processed at all?
Does someone know how to do this? To read a PDF file, stored in the DB - and display to the user?
Please, help is needed.
This is the code where I try to display the PDF (Not working)
<?php require_once("includes/config.php"); ?>
<?php require(MYSQL); ?>
<?php
$valid = false;
if(isset($_GET['id'])&&(strlen($_GET['id'])==40)&&(substr($_GET['id'],0,1)!='.')){
$file = PDFS_DIR .$_GET['id'];
//echo $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);
$description = $row[3];
$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);
//die();
}
}
}
?>
<?php
// Further down the page:
if($valid != true){ // error msg.
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>';
}else {
echo "<div>$description</div>";
}
?>
I have defined the PDF_DIR like this: (Is that correct?)
define('PDFS_DIR', $_SERVER['DOCUMENT_ROOT']);
Is this part correct?