The equipment:
Windows 2000 server and phpdev 4.2.3 (php, apache, mysql)
I have a simple page, where the user can download some documents (pdf, doc). It seems to work fine with
browsers except Internet Explorer (I have tested with Netscape, Mozilla and Opera). The site uses sessions without using cookies.
The problem is as follows (the code is in the end of message):
Case 1, works fine:
- Open the link page (contains "download forms")
- Click "Load" and save or open the document
- Click "Load" and save or open (the same or some other document)
WITHIN ABOUT 15 SECONDS from the previous download
Case 2, DOES NOT WORK (gives "The page cannot be displayed")
- Open the link page
- Click "Load" and save or open the document
- Click "Load" and save or open (the same or some other document)
WHEN OVER 15 SECONDS HAVE ELAPSED FROM THE PREVIOUS DOWNLOAD
Case 3, works fine:
- same as "case 2", but there is a AUTOREFRESH (ten seconds) in the Linkpage.htm
Case 4, works fine:
- Open the link page
- Wait a minute or two
- Click "Load" and save or open the document
Seems like something weird happens after the file open/download, and I can't figure out what it could be. I think
this could have something to do with the Apache and the "KeepAlive", because in the httpd.conf file the
"KeepAliveTimeout" is set to "15".
Any clue about what the problem is, and how can I manage to get this workin without the autorefresh????
Here is the essential part of the code:
First page: (Linkpage.htm)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="Loaddocument.php/" method="post" target="_parent">
<input type="hidden" name="document" value="Document1.pdf">
<input type="submit" value="Load">
</form>
<BR><BR>
<form action="Loaddocument.php/" method="post" target="_parent">
<input type="hidden" name="document" value="Document1.pdf">
<input type="submit" value="Load">
</form>
<BR><BR>
etc.....
Second page: "Loaddocument.php"
<?php
include_once("config.php"); //This contains also the function "DownloadFile($filename)"
$document = $HTTP_POST_VARS["document"];
$filename = "c:\dir\dsubdir\" . "$document";
DownloadFile($filename);
?>
The actual download function:
function DownloadFile($filename)
{
if (empty($filename) || !file_exists($filename))
{
return FALSE;
}
$saveasname = basename($filename);
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($filename));
if (preg_match('/MSIE 5.5/', $_ENV['HTTP_USER_AGENT'])
|| preg_match('/MSIE 6.0/', $_ENV['HTTP_USER_AGENT']))
{
header('Content-Disposition: filename="'.$saveasname.'"');
}
else
{
header('Content-Disposition: attachment; filename="'.$saveasname.'"');
}
header('Content-Transfer-Encoding: binary');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
readfile($filename);
return TRUE;
}