The role and usage of Content-Disposition in the header. Content-disposition is an extension of the MIME protocol. The MIME protocol instructs the MIME user agent how to display additional files. Content-disposition can actually control the Content obtained by the user request to be stored as a Content-disposition extension of the MIME protocol. The MIME protocol instructs the MIME user agent how to display the attached files. Content-disposition can actually control whether the Content requested by the user is saved as a file and provide a default file name. The file is displayed directly in the browser or a file download dialog box is displayed during access.
Format Description:
Content-disposition = "Content-Disposition": "disposition-type * ("; "disposition-parm)
Field description:
Content-Disposition: attribute name
How is disposition-type downloaded, for example, attachment?
Disposition-parm is the default file name for saving
When the server sends a file to the client browser, if the file type is supported by the browser, it is generally opened by default using a browser, such as txt and jpg, and will be directly displayed in the browser, if you need to prompt the user to save, use Content-Disposition for processing. The key is to add attachment:
The code is as follows:
Response. AppendHeader ("Content-Disposition", "attachment?filename=filename.txt ");
Note: In this case, the browser will prompt whether to save or open the file. even if you choose to open the file, it will also use the associated program, such as Notepad, instead of opening the file directly by IE.
Content-Disposition provides a default file name when you want to save the requested Content as a file. The specific definition is as follows:
The 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)
The specific example is as follows:
Content-Disposition: attachment; filename = "filename.xls"
Of course, the filename parameter can contain path information, but User-Agnet ignores this information and only uses the last part of the path information as the file name. If you use this header when the response type is application/octet-stream, it means that you do not want to directly display the content, but instead pop up a "file download" dialog box, the next step is to "open" or "save.
Note:
1. when Content-Disposition is used in the code to ensure that the download dialog box is displayed in the browser. Response. addHeader ("Content-Disposition", "attachment"); make sure that you have not performed any operations to prohibit browser caching. As follows:
The 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 is okay in opera and firefox, but not in IE.
The http://www.bkjia.com/PHPjc/325564.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325564.htmlTechArticleContent-disposition is an extension of the MIME protocol, which instructs the MIME user agent how to display additional files. Content-disposition can actually control the Content obtained by the user request to be stored...