
Untitled
By: a guest on
Apr 24th, 2012 | syntax:
None | size: 1.05 KB | hits: 15 | expires: Never
View a PDF file in HTML not to download it
<a href="pdffile.pdf"> PDF 1 here </a>
<a href="view.php?download_file=MIKOGO Remote Support.pdf"><img src="images/view.png" alt=" " border="0"/></a>
<?php
$path = $_SERVER['DOCUMENT_ROOT']."/demo/documents/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: inline; filename="".$path_parts["basename"].""");
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename="".$path_parts["basename"].""");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
?>