Click to See Complete Forum and Search --> : Force download doesn't work with IE7 on remote server


godbout
03-18-2008, 02:55 AM
Hi there,

I've got a really strange problem and I've already spent too much time on it for the small thing it is.

I've got 2 php pages. One is the main one, calling the second one. The second is just a page to force the download of a file.
When I use them locally, I don't have any problem. It works well with IE and FF. The 'Save dialog box" appears in both cases, and I case save or open my file perfectly.

But when I put the file on my remote server, it works well with FF but doesn't work anymore with IE7. IE7 opens the second page but close it automatically and immediately. The "Save dialog box" never appears, and I cannot find the reason.

After 2 days of trying to understand what's happening, I gave up (quite often with IE).
I chose another solution, not the one I wanted, but I cannot loose too much time with that.

Anyway, I would still understand what's happening, if anybody gets an idea.

Here is the code used:

In the main page, to call the second php file

echo '<script language="JavaScript">window.open(\'dl.php?filename=' .basename( $appFile ) .'\',\'download\')</script>';


The second page

<?php
$filename = '../appFiles/'. $_GET['filename'];

if ( substr(strrchr($filename, '.'), 1) == 'xls' )
{

if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
readfile("$filename") or die("File not found.");
}
?>


Thanks for your help!

NogDog
03-18-2008, 03:47 AM
Have you tried it without the zlib stuff, just to see if maybe that's the issue? (I've never tried using it like that, so have no idea if it could be a problem or not.)

If that's not it, I've had success using just the following headers to force a download:

header('Content-Length: '.$fileSize);
header('Content-Type: '.$mimeType);
header('Content-Disposition: attachment; filename="'.$fileName.'"');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');

godbout
03-19-2008, 02:08 AM
NogDog, thanks for you answer :)

I tried without the zlib stuff yep, actually it wasn't there at the beginning, I added it later but without effects :/

I'll try to copy exactly your code, but it looks like I did that already many times without success :D

I tell you if it works!

Thanks

godbout
03-19-2008, 02:28 AM
It doesn't work :-/

As before, it works great with FF, both local and remote.
But it works for IE only in local, not in remote. The popup opens and closes directly, with a sound like when a popup is blocked, but it's not the case (if I do an echo 'blabla'; the popup opens). I just don't have the Save dialog :-/

Any other suggestion?
Do you think the problem could be from the server side?

Thanks,

NogDog
03-19-2008, 02:52 AM
I didn't catch the JavaScript part of this earlier. Could it be a pop-up blocker issue? If so, you might need to make the window.open() call part of an onclick event instead of just a direct <script> call, e.g.:

$dlFile = 'dl.php?filename=' . urlencode(basename($appFile));
echo '<a href="'.$dlFile.'" onclick="window.open(\' . $dlFile .
'\',\'download\');return false;">Click to download</a>';

godbout
03-19-2008, 04:16 AM
Thanks, I'll try that because I take everything I get now :D
But one thing is that I turned off the popup-blocker to see if this was the problem and the problem still occur, a second thing is that it works on my local machine, and a third thing is that I want the window to be opened in this way and not with a link. If I do it with a link, so I don't need this dl.php anymore but use a direct link instead :)

But let me try, and I'll give you the result.

godbout
03-19-2008, 05:56 AM
It works.
So, I don't really get the point here. I ask IE to turn off the popup-blocker but it still block the popup?

Thanks anyway, I've got a start of answer, and I'll stop worrying about that :D

NogDog
03-19-2008, 03:22 PM
Glad you got something to work. I'm afraid we're getting out of my "guru zone" ;) when it comes to what's going on here, though. If you run into any useful info about this, please post it back here, as I'd be curious to know.

godbout
03-20-2008, 02:28 AM
Ok, thanks a lot anyway.
I guess that the answers to my questions are: Microsoft :o