By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,167 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

download via header using flush()?

P: n/a
hi,
i'm looking for a possibility to start a download.

here is my current code:
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
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Thomas Kemmerich wrote:
hi,
i'm looking for a possibility to start a download.

here is my current code:
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

Why wouldn't Content-size help you? Have you tried it? I believe that
is what you are looking for. If you want to avoid all of this stuff,
just do a header redirect via Location.

-Calico Jack-

Jul 17 '05 #2

P: n/a
Calico Jack <sg****@yahoo.com> wrote in message news:<7I*****************@bignews5.bellsouth.net>. ..
Thomas Kemmerich wrote:
hi,
i'm looking for a possibility to start a download.

here is my current code:
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

Why wouldn't Content-size help you? Have you tried it? I believe that
is what you are looking for. If you want to avoid all of this stuff,
just do a header redirect via Location.

-Calico Jack-

I use these
header("Content-type: Aplication/Octet-Stream");
header("Content-disposition: filename=$your_file_name");
header("Content-length: number_of_bytes");
header("Filename: $your_file_name");

while(readfile....)
print file_contents;

Mike Bradley
http://gzen.myhq.info -- free online php tools
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.