download via header

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
micrix
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2003 4:18 am

download via header

Post by micrix »

hi,
i'm looking for a possibility to start a download.

here is my current code:

Code: Select all

header("Content-Type: $_contenttype");
		header("Content-Disposition: attachment; filename="$_filename"");
		// flush();
		echo $filecontent;
this works fine. however i'm not satisfied with that code because it seems as if the code first creates the complete file and then sends the output to the browser. then the browser starts the downloadaction and the filesize is always 1kb.

what i want the code to do is to start a normal download.
$filecontent will be created after sending the header (this is because the file is decoded from an email - $filecontent is an email-attachment).

what i've tried out is adding flush(); after sending the header. i thought the browser would start the download dialog - however it doesn't!

is there an additional header-tag that might help me? i've read something about "content-size: filesize($file)". but i don't believe that this might help me!

greets micrix
micrix
Forum Newbie
Posts: 7
Joined: Thu Jun 12, 2003 4:18 am

Post by micrix »

does nobody know how to solve my problem?
Post Reply