Headers and IE7

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Monstamash
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2008 11:15 am

Headers and IE7

Post 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
Attachments
error.gif
error.gif (12.57 KiB) Viewed 971 times
Last edited by Monstamash on Wed Nov 19, 2008 11:38 am, edited 1 time in total.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Headers and IE7

Post 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
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Headers and IE7

Post by andyhoneycutt »

Please post your javascript code if you are using any.
Monstamash
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2008 11:15 am

Re: Headers and IE7

Post 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
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Headers and IE7

Post 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?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Headers and IE7

Post 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
Monstamash
Forum Newbie
Posts: 5
Joined: Wed Nov 19, 2008 11:15 am

Re: Headers and IE7

Post 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!
Post Reply