At 06:39 15.11.2002, Twist said:
--------------------[snip]--------------------
>       This is all great, the problem is that it loads a new page 
>the way I am doing it.  I am using the header() function to get the 
>browser to download.  I have seen sites with counters that download 
>the file and update the count without loading a new page, without 
>reloading the current page even.  So I am wondering how are they 
>doing this?  Or better yet how can I get my script to work like I 
>wish it to?
--------------------[snip]-------------------- 

With MIME (and HTTP is MIME-compliant) you can transmit more than one
entity in a single pass - this is called "multipart" transmission. The
recipient (here: the browser) should handle all parts of a multipart
message per se.

What you need to do is to set the content type of the response to
multipart/alternative, and transmit the HTML result first, and the file
content next. Both parts are delimited by a boundary string, and each part
has its own MIME header.

Something like:

// construct the "alternative" hader for the site's response
$boundary = md5(date('hisjmy'));
header("Content-type: multipart/alternative; boundary=\"$boundary\"");

// The HTML page starts with a boundary and its own MIME header
$html_head = "--$boundary\n" .
             "Content-Type: text/html\n" .
             "Content-Disposition: inline\n\n";

// The Attachment starts with another MIME header
$attach_head = "\n--boundary\n" .
               "Content-Type: application/octet-stream\n" .
               "Content-Transfer-Encoding: base64\n" .
               "Content-Disposition: attachment;\n" .
               "      filename=\"$filename\"";

Your response would then look something like this:

echo $html_head;
echo $html_page_contents;
echo $attach_head();
transmit_file_content();
echo "\n--$boundary\n";

This is top off my head, but it should work. For more information on
multipart responses you might consult

ftp://ftp.rfc-editor.org/in-notes/rfc2045.txt (MIME Part I)
ftp://ftp.rfc-editor.org/in-notes/rfc2046.txt (MIME Part II)
ftp://ftp.rfc-editor.org/in-notes/rfc2047.txt (MIME Part III)
ftp://ftp.rfc-editor.org/in-notes/rfc2183.txt (Content-Disposition)


-- 
   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035
    ^     http://www.vogelsinger.at/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to