download via header using flush()?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thomas Kemmerich

    #1

    download via header using flush()?

    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=\"$_fi lename\"");
    // 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
  • Calico Jack

    #2
    Re: download via header using flush()?

    Thomas Kemmerich wrote:[color=blue]
    > 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=\"$_fi lename\"");
    > // 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[/color]
    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-

    Comment

    • CountScubula

      #3
      Re: download via header using flush()?

      Calico Jack <sglane@yahoo.c om> wrote in message news:<7IRHb.529 0$sb4.2528@bign ews5.bellsouth. net>...[color=blue]
      > Thomas Kemmerich wrote:[color=green]
      > > 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=\"$_fi lename\"");
      > > // 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[/color]
      > 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-[/color]


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

      while(readfile. ...)
      print file_contents;



      Mike Bradley
      http://gzen.myhq.info -- free online php tools

      Comment

      Working...