/    Sign up×
Community /Pin to ProfileBookmark

Force download doesn’t work with IE7 on remote server

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

[code]
echo ‘<script language=”JavaScript”>window.open(‘dl.php?filename=’ .basename( $appFile ) .”,’download’)</script>’;
[/code]

The second page

[code]
<?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.”);
}
?>
[/code]

Thanks for your help!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMar 18.2008 — 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:
[code=php]
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');
[/code]
Copy linkTweet thisAlerts:
@godboutauthorMar 19.2008 — 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 ?

I tell you if it works!

Thanks
Copy linkTweet thisAlerts:
@godboutauthorMar 19.2008 — 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,
Copy linkTweet thisAlerts:
@NogDogMar 19.2008 — 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.:
[code=php]
$dlFile = 'dl.php?filename=' . urlencode(basename($appFile));
echo '<a href="'.$dlFile.'" onclick="window.open(' . $dlFile .
'','download');return false;">Click to download</a>';
[/code]
Copy linkTweet thisAlerts:
@godboutauthorMar 19.2008 — Thanks, I'll try that because I take everything I get now ?

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.
Copy linkTweet thisAlerts:
@godboutauthorMar 19.2008 — 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 ?
Copy linkTweet thisAlerts:
@NogDogMar 19.2008 — 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.
Copy linkTweet thisAlerts:
@godboutauthorMar 20.2008 — Ok, thanks a lot anyway.

I guess that the answers to my questions are: Microsoft :o
×

Success!

Help @godbout spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...