I am using the following code to open a pdf document. The pdf document is stored outside of the root directory:

$file = $_GET['file'];
    $fileDir = '../../c_direc/';

    if (file_exists($fileDir . $file))
        $contents = file_get_contents($fileDir . $file);

        header('Content-type: application/pdf');

        echo $contents;

This code works (the pdf file opens) in firefox/Opera/Safari.. however in Internet Explorer, I am just getting a blank page.

Any suggestions are very much appreciated!

8 Years
Discussion Span
Last Post by FlashCreations

I am using an ajax call to open all pdf files in a new window:

    $("a[href$='.pdf'], a[href$='.doc'], a[href$='.xls']").click(function () {
     	var features = "height=600,width=700,scrollTo,resizable=1,scrollbars=1,location=0";
      	newwindow=window.open(this.href, 'Popup', features);
      	return false;


When I remove the ajax code, the pdf opens in the browser. Not sure why this only causes a problem with IE (tried in version 7 & 8).


It's probably a missing header, IE is always picky! One thing to note though if what if I was a user and I entered "htdocs/index.php" or "www/index.php"? With some luck you script would print out the code stored inside the index.php file (The browser would confuse it for a PDF, but any advanced computer user could fix this). I would suggest altering you code a little:

$file = str_replace("/", "", str_replace("\", "", $_GET['file'])); //Safe file name
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.