Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. View a PDF file in HTML not to download it
  2. <a href="pdffile.pdf"> PDF 1 here </a>
  3.        
  4. <a href="view.php?download_file=MIKOGO Remote Support.pdf"><img src="images/view.png" alt=" " border="0"/></a>
  5.        
  6. <?php
  7.  
  8. $path = $_SERVER['DOCUMENT_ROOT']."/demo/documents/"; // change the path to fit your websites document structure
  9. $fullPath = $path.$_GET['download_file'];
  10.  
  11. if ($fd = fopen ($fullPath, "r")) {
  12. $fsize = filesize($fullPath);
  13. $path_parts = pathinfo($fullPath);
  14. $ext = strtolower($path_parts["extension"]);
  15. switch ($ext) {
  16.     case "pdf":
  17.     header("Content-type: application/pdf"); // add here more headers for diff. extensions
  18.     header("Content-Disposition: inline; filename="".$path_parts["basename"].""");    
  19.     break;
  20.     default;
  21.     header("Content-type: application/octet-stream");
  22.     header("Content-Disposition: filename="".$path_parts["basename"].""");
  23. }
  24. header("Content-length: $fsize");
  25. header("Cache-control: private"); //use this to open files directly
  26. while(!feof($fd)) {
  27.     $buffer = fread($fd, 2048);
  28.     echo $buffer;
  29. }
  30. }
  31. fclose ($fd);
  32. exit;
  33. ?>