Content-disposition is an extension of the MIME protocol, and the MIME protocol indicates how the MIME user agent displays additional files. Content-disposition can actually control when the user requests the content to save as a file, provide a default file name, the file is displayed directly in the browser or the File Download dialog box when accessed.
Format Description:
Content-disposition = "Content-disposition" ":" Disposition-type * (";" Disposition-parm)
Field Description:
Content-disposition is a property name
How Disposition-type is downloaded, such as attachment for download by attachment
Disposition-parm is the file name when it is saved by default
When the server sends a file to the client browser, if it is a file type supported by the browsers, it will usually be opened by default browser, such as txt, JPG, etc., will be displayed directly in the browser, if you need to prompt the user to save, we should use content-disposition to do a bit of processing, The key is to be sure to add attachment:
Copy CodeThe code is as follows:
Response.appendheader ("Content-disposition", "attachment;filename=filename.txt");
Note: This will prompt the browser to save or open, even if you choose to open, will also use the associated program such as Notepad open, instead of IE directly opened.
Content-disposition is to provide a default file name when the user wants to save the requested content as a file. The specific definitions are as follows:
Copy CodeThe code is as follows:
Content-disposition = "Content-disposition" "": "
Disposition-type * (";" Disposition-parm)
Disposition-type = "Attachment" | Disp-extension-token
Disposition-parm = Filename-parm | Disp-extension-parm
Filename-parm = "FileName" "=" quoted-string
Disp-extension-token = Token
Disp-extension-parm = Token "=" (token | quoted-string)
so the concrete examples are:
Content-disposition:attachment; Filename= "Filename.xls"
Of course, the filename parameter can contain path information, but user-agnet ignores the information and only makes the last part of the path information the file name. When you use this header message in response type Application/octet-stream, it means that you don't want to display the content directly, but instead pop up a "File download" dialog box, and then you decide whether to "open" or "save".
Precautions :
1. When the code uses Content-disposition to ensure that the browser pops up the download dialog box. Response.AddHeader ("Content-disposition", "attachment"); Make sure you haven't done anything about prohibiting browser caching. As follows:
Copy CodeThe code is as follows:
Response.setheader ("Pragma", "No-cache");
Response.setheader ("Cache-control", "No-cache");
Response.setdateheader ("Expires", 0);
Otherwise you will find that the download function in opera and Firefox is good, under IE is not OK
http://www.bkjia.com/PHPjc/325564.html www.bkjia.com true http://www.bkjia.com/PHPjc/325564.html techarticle Content-disposition is an extension of the MIME protocol, and the MIME protocol indicates how the MIME user agent displays additional files. Content-disposition can actually control the contents of the user request to save as a ...