Page 1 of 1

file download problem

Posted: Thu Feb 20, 2003 2:29 pm
by kcomer
I have this ocde and it doesn't work as expected. I would like the user to be propmted to download a file named. test.txt with the content from $document. Can anyone shed some light on why this wont work?

Code: Select all

<?php

$document = "This is what I want in the file\n\nLine 3";
$length = strlen($document);
$filename = "text.txt";

header("Content-Type: application/octet-stream");
header("Content-Length: " . $length);
header("Content-Disposition: inline; filename=" . $filename);

return($document);

?>
Here is a link to the code.
http://www.mana-ts.com/dl_test.php

Keith

Posted: Thu Feb 20, 2003 3:17 pm
by hob_goblin
try

Code: Select all

<?php 

$document = "This is what I want in the file\n\nLine 3"; 
$length = strlen($document); 
$filename = "text.txt"; 

header("Content-Type: application/octet-stream"); 
header("Content-Length: " . $length); 
header("Content-Disposition: inline; filename=" . $filename); 

echo $document; 

?>

Posted: Thu Feb 20, 2003 3:51 pm
by kcomer
Nope, just prints to the screen now.

Posted: Thu Feb 20, 2003 4:16 pm
by hob_goblin

Posted: Thu Feb 20, 2003 4:59 pm
by kcomer
works for me in netscpae but not ie.

Posted: Thu Feb 20, 2003 10:26 pm
by Stoker
When disp is attachement IE will usually ask you about "Open from location" or "Save", there is no way around that, if you select "Don't ask me again" it is locked on that..

The whole point of using disp/attach is to allow for save-as instead of inline opening which is quite normal (and anoying) for pdf and othe docs..

Posted: Thu Feb 20, 2003 10:27 pm
by Stoker
btw, if it is a text file, don't use Application/Octet-stream, use text/plain instead (type)