Page 1 of 1

Headers and IE7

Posted: Wed Nov 19, 2008 11:30 am
by Monstamash
Hi All,

I just started php a couple of months ago, beggining to get the hang of things. But one big problem I am having is with IE 7 and using headers to display a pdf. I have a link which opens a new window using javascript. The new window users headers to display the pdf. I have cut out all the validation stuff, essentially I have:

Code: Select all

 
$file = "../reports/{$_GET['file']}";
$name = $_GET['file'];
$fs = filesize($file);
 
header ("Content-Type: application/pdf");
header ("Content-Disposition: inline; filename=$name");
header ("Content-Length: $fs");
readfile ($file);
 
It works fine in Firefox IE 5.5, 6 and IE 7.0.5730.11 but not on IE 7.0.5730.13!

Drove me mad till I reasised what the problem was. Can anyone confirm that my code is ok, and that it is some kind of bug in the latest version of IE? Is there anyway round this to fix it?

The image attached is the error I am getting. Looks more like a JS error than a php, but I just don't know!

Thanks

Andy

Re: Headers and IE7

Posted: Wed Nov 19, 2008 11:37 am
by andyhoneycutt
I recently had some users complaining about not being able to download reports from the site I work on. I was able to nail the problem down to IE, and found that by adding this to the header, things worked...Let me know if this works for you.

Code: Select all

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
-Andy

Re: Headers and IE7

Posted: Wed Nov 19, 2008 11:40 am
by andyhoneycutt
Please post your javascript code if you are using any.

Re: Headers and IE7

Posted: Wed Nov 19, 2008 11:54 am
by Monstamash
Hi Andy - Thanks for taking the time to reply

Unfortunatly the extra headers didn't make any difference, exact same error.

The code I am using is:

Code: Select all

 
 
<script language="JavaScript">
    <!-- // Hide from old browsers.
    
    // Make a pop-up window function:
    function create_window (image) {
        
        // Set the window properties:
        var specs = "location=no, scrollbars=no, menubars=no, toolbars=no, resizable=yes, fullscreen=yes";
        
        // Set the URL:
        var url = "download_file.php?file=" + image;
        
        // Create the pop-up window:
        popup = window.open(url, "Report_Window", specs);
        popup.focus();
        
    } // End of function.
    //--></script>
 

and

Code: Select all

 
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$sn = strtolower($row['ship_name']);
$sn = str_replace(" ", '', $sn);
$count1 = 1;
foreach ($files as $report) {
    if (strtolower(substr($report, 0, strlen($sn))) == $sn) { // Lower case Shipname start of report name.
        if ($count == 1) {
             echo "<p>The following report(s) is available for download.</p><br />";
        } 
        
        echo "<p><a href=\"javascript&#058;create_window('$report')\">" . $row['ship_name'] . " Report " . $count1 . "</a></p>";
 
        $count1++;
        $count2++;
 
    }
    
} //End For
echo '<br />';
} //End While
 
Cheers

Re: Headers and IE7

Posted: Wed Nov 19, 2008 11:56 am
by mmj
Hmm... are you sure you are saving download_file.php in plain ascii text and you have no extra characters at the top?

Re: Headers and IE7

Posted: Wed Nov 19, 2008 12:02 pm
by andyhoneycutt
I am failing to see a problem here. I'll keep you posted if I can figure this out for you. At first I thought it was the &-notation that your snip is showing, but then i realized that's how the bb code is posting it ;)

-Andy

Re: Headers and IE7

Posted: Thu Nov 20, 2008 3:52 am
by Monstamash
Thanks for your help guys.

I managed to find another PC with IE 7.0.5730.13 and guess what, it worked fine. Must be something strange with set up of the PC I was developing on. Only about 5 hours of my life wasted :banghead:

Cheers for all your help!