Here's some snippets of code that I use to send a textfile; to generate the
link that the user clicks on to download the file (sorry for the mess, I cut it
straight out of the ASP script!):

print "<a href=\"index.asp?f=sa;id=", $href->{'id'}, "\" title=\"",
$href->{'uzfname'}, "\" type=\"application/octet-stream\">",
$href->{'uzfname'},"</a>";

When they click on that link, the following is executed in an ASP script:

$Response->{'ContentType'} = 'application/octet-stream;name=' . 
$file_href->{'uzfname'};
$Response->{'ContentLength'} = $file_href->{'size'};
$Response->AddHeader('Content-Disposition', 'Attachment;filename=' . 
$file_href->{'uzfname'});

while ($i = read(FH, $data, 10000))  # read file..
{
        $Response->Write($data);  # and send it
}


The way different browsers handle this seems to vary; some will, for example,
not get the filename right when you right-click on the link and select "Save
target link as". But then, I arrived at the above method mostly by
experimenting, so it may not be the correct way of doing it.

Cheers,

/Anders


On Thu, 9 Aug 2001 18:29:31 -0400, Stephen Bardsley said:

> Greetings,
>  
>  I am printing data from a script directly back
>  to the browser.  The data is text but not HTML.
>  I have changed the ContentType, which in turn
>  forces the "SaveAs" dialog to be raised.  So
>  far so good...
>  
>  What I would like to do is dictate the default
>  file name in the "SaveAs" dialog.  Can it be done?
>  Thanks.
>  
>  Steve
>  _____________________
>  Stephen Bardsley
>  RLW Inc.
>  Malta, NY 
>  
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: [EMAIL PROTECTED]
>  For additional commands, e-mail: [EMAIL PROTECTED]
>  
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to