Forum Moderators: coopster

Message Too Old, No Replies

Problem about fclose.

file download

         

skpippen

2:32 am on Jan 10, 2006 (gmt 0)

10+ Year Member



Hi,

I have the following script in my site.

$file_dir = "./";
$myFileName="test.txt";

$file = fopen($file_dir.$myFileName,"r");
if (!$file)
{
show_msg("File not open.");
}
else
{
Header("Content-type: application/octet-stream");
Header("Content-Disposition: attachment;
filename=" . $myFileName);

while (!feof ($file))
{
echo fread($file,50000);
}
fclose ($file);
header("Location: http://www.example.com/ok.php");
}

The file can be downloaded successfully, but the problem is the last statement dose not execute.

Anyone can help me?

Thanks very much.

Hester

4:45 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Headers have to be issued BEFORE anything else, usually at the top of the script.