Page 1 of 1

(HTTP headers SSL) File download with SSL and IE.

Posted: Tue May 06, 2003 7:51 am
by Heavy
Yes! One more time. Those of you that are here often must have seen me about ALMOST this before.
This time, it is about IE, PHP-file download with data from mysql and SSL.
When trying to download a file with my script "https://blabla.com/file-download.php?ID=12345" there are two errors showing:

1: The "Save as..." popup suggests the request string instead of the file name.
2: IE says "Can't find the page" after a few seconds of trying.
Note: This error only occurs with IE.
OF COURSE everything works perfectly with MZ and NS7.

Here is the faulty php script "file-download.php":

Code: Select all

<?php
session_cache_limiter('private');
define('NO_HEADERS',1); //tells functions.php not to send any headers.
define('IN_SYSTEM',1);
require "functions.php"; //connects to DB, defines some functions and starts the session.
//also, the "functions.php" secures $_GET with addslashes() (in case anyone dislikes the query below.)

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);


$File = mysql_query_get_first_row("select distinct t1.*, t2.Txt as FileName from PermRead t3 
											left join Files t1 on t3.TodoID=t1.TopicID
											left join Topics t2 on t1.TopicID=t2.ID 
										where t3.TopicID='{$_GET['ID']}' and t3.UserID = '{$_SESSION['LoggedInID']}' and t2.IsFile=1");
										
if ($File !== false){

	header("Content-Length: ".$File['Size']);
	header("Content-type: ".$File['MimeType']);

	if ($BrowserIsGecko){
		header("Content-Disposition: attachment; filename='".(str_replace(Array("Å","å","Ä","ä","Ö","ö"),Array("A","a","A","a","O","o"),$File['FileName']))."'");
	}else{
		header("Content-Disposition: attachment; filename="".$File['FileName'].""");
	}
	$Content = mysql_query("select Content from FileContent where FileID={$File['ID']} order by ID");
	if (mysql_num_rows($Content)){
		while ($Row = mysql_fetch_row($Content)){
			echo $Row[0];
		}
	}
	Accesslog("Downloading File");
}else{
	Accesslog("File Download Failure");
	echo '
<html><head><link rel="StyleSheet" href="main.css" type="text/css"></head>
<body><table height="100%" align="center"><tr><td valign="middle" align="center">
Error. The system could not find the file.<br><br><a href="overview.php?WhatNow=View">Go Back</a>
</td></tr></table></body></html>
';
}
?>
What can I do with those headers to bust this behaviour of IE?

Posted: Tue May 06, 2003 11:57 am
by volka

Code: Select all

<?php
$Content = 'test';
header("Cache-Control: no-store");
header('Content-Length: '.strlen($Content));
header('Content-Type: application/octet');
header('Content-Disposition: attachment; filename="test.dat"');

echo $Content;
?>
seems to be enough to confuse IE. Without the Cache-Control it's working.

Posted: Tue May 06, 2003 3:31 pm
by Heavy
Seems like it worked...
:D
Is this correct behaviour? I mean, IE gets it as intended WITH those headers, and NOT using SSL.

Is this some kind of limitation due to the SSL-protocol and Apache (which I am using on this machine)?

Or is it poor MS engineering? (again)

(I don't like the fact that I spend more than 50% of the development time wrestling with IE. ...At least it feels like that. A fact, is that IE makes me more tired in one day than the rest of the development does in a month.)

Big thanks.

I hope it works for our students spread out over sweden aswell.