Hello. I am having a hard time in figuring out how to view the pdf file after uploading it in your system. My plan is retrieved PDF files that is stored in mysql database and display them in the browser when the user click the view button. please help me. Currently, here is my code..

<?php
if (isset($_GET['id'])) {
$file = $_GET['id'];
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) {
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
} else {
header("HTTP/1.0 404 Not Found");
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
}
?>

it doesn't displaying the pdf file. please help me. thank you..

Hi,
Some setups will download the file instead of displaying in the browser. Have you checked it is not downloading without displaying?

Also (very small point) is_readable() checks if file exists so file-exists() is not necessary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.