file download problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

file download problem

Post 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
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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; 

?>
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

Nope, just prints to the screen now.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

works for me in netscpae but not ie.
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post 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..
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

btw, if it is a text file, don't use Application/Octet-stream, use text/plain instead (type)
Post Reply