0

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..

2
Contributors
1
Reply
9
Views
3 Years
Discussion Span
Last Post by nauticalmac
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.