At 06:39 15.11.2002, Twist said:
>       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?

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();
echo "\n--$boundary\n";

This is top off my head, but it should work. For more information on
multipart responses you might consult (MIME Part I) (MIME Part II) (MIME Part III) (Content-Disposition)

   >O     Ernest E. Vogelsinger
   (\)    ICQ #13394035

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to