2

I've a little problem. On my server i've several pdf files saved outside the public folder. I want to display those files on my website.

The code to display the pdf I use now:

$pdf = '/var/www/vhosts/domain.com/users/'.$_GET['file']; 
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="'.$pdf.'"'); 
readfile($pdf);

What I do now is display them via an iFrame but on IE8 i'll get the message to save the file to my computer. On chrome and IE9 there are no problems.

Is there a better way to display the pdfs?

Leon van der Veen
  • 1,652
  • 11
  • 42
  • 60

3 Answers3

3

please look up this question, the user had the same question as you: Show a PDF files in users browser via PHP/Perl

I also have a security notice for your:

THIS: $pdf = '/var/www/vhosts/domain.com/users/'.$_GET['file']; Can be extremly dangerous, imagine if some one modifies your url parameter like this: yoursite.php?file=../../index.php

If you are not very careful here, people can download other files from your server... so please be careful and validate your $_GET['file'] before using it.

Regards

Community
  • 1
  • 1
Grrbrr404
  • 1,809
  • 15
  • 17
0

I think if you leave you: content-disposition: inline and change it to content-disposition: filename="'.$pdf.'" the browser will determine what to do with the PDF. If there is a plugin for pdf installed it will use that one.

Arend
  • 3,741
  • 2
  • 27
  • 37
  • 1
    unfortunately this doesn't work either. On IE8 I still get the message "Internet Explorer blocked this site from downloading files to your computer". Adobe reader 10 is installed... – Leon van der Veen Nov 21 '11 at 13:23
  • Is this not an ie8 specific question then? – Arend Nov 21 '11 at 14:12
-1
$pdf = '/var/www/vhosts/domain.com/users/'.$_GET['file']; 
header('Content-Disposition: inline; filename="'.$pdf.'"');// download header 
readfile($pdf)  //read our file and shows on website
Mp0int
  • 18,172
  • 15
  • 83
  • 114