prompting download using header()

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

    prompting download using header()

    hi,

    i have been tryin to prompt the download of a file on the server using
    the following code:

    // send headers, forcing download:
    header("Content-type: application/word");
    header("Content-Disposition: attachment;
    filename=\"file s/myfile.doc\"");


    ....where myfile.doc in folder files is a file on the server relative
    to the script:


    Warning: Cannot modify header information - headers already sent by
    (output started at /home/marty27/public_html/test/oarsome/test_prompt.php :8)
    in /home/marty27/public_html/test/oarsome/test_prompt.php on line 10

    Warning: Cannot modify header information - headers already sent by
    (output started at /home/marty27/public_html/test/oarsome/test_prompt.php :8)
    in /home/marty27/public_html/test/oarsome/test_prompt.php on line 11


    can anyone tell me what i am doin wrong? i have read the php manual
    thingy and to my primitive knowledge, this would work. any help?
    cheers

    burnsy
  • Frank R. Suchy

    #2
    Re: prompting download using header()

    Am 30 Jul 2004 15:25:31 -0700 schrieb mr_burns:
    [color=blue]
    > hi,
    >
    > i have been tryin to prompt the download of a file on the server using
    > the following code:
    >
    > // send headers, forcing download:
    > header("Content-type: application/word");
    > header("Content-Disposition: attachment;
    > filename=\"file s/myfile.doc\"");
    >
    >
    > ...where myfile.doc in folder files is a file on the server relative
    > to the script:
    >
    >
    > Warning: Cannot modify header information - headers already sent by
    > (output started at /home/marty27/public_html/test/oarsome/test_prompt.php :8)
    > in /home/marty27/public_html/test/oarsome/test_prompt.php on line 10[/color]

    You cannot use header() when the script allready has sent data to the
    client.
    This "Warning" says, the script (test_prompt.ph p) has allready done some
    output on line 10. So have a closer look there...

    And take a closer look at the php manual at

    somewhere halfway through it says "Remember that header() must be called
    before any actual output is sent,..."
    Maybe take a look at headers_sent() as well.

    hth,
    Frank

    Comment

    Working...