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!

Recommended Answers

All 2 Replies

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

$(document).ready(function(){
	
    $("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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.