Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Content-disposition

2025-01-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Content-disposition is an extension of the MIME protocol, which instructs the MIME user agent how to display additional files. When Internet Explorer receives the header, it activates the file download dialog box, and its file name box is automatically populated with the file name specified in the header. (note that this is caused by design; you cannot use this feature to save the document to the user's computer without asking the user where to save it. )

When the server sends a file to the client browser, if it is a file type supported by the browser, it will be opened by default in the browser, such as txt, jpg, etc., which will be directly displayed in the browser. If you need to prompt the user to save, you must use Content-Disposition to deal with it. The key is to add p_w_upload:

Response.AppendHeader ("Content-Disposition", "paired filename filename. Txt")

Note: this way the browser will be prompted to save or open, and even if you choose to open it, it will open it using the associated program such as notepad, rather than IE directly.

Content-Disposition is to provide a default file name when the user wants to save the content of the request as a file. The specific definition is as follows:

Content-disposition = "Content-Disposition":"

Disposition-type * (";" disposition-parm)

Disposition-type = "p_w_upload" | 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 from the above, we can know the specific examples:

Content-Disposition: paired filename.xls; filename= "filename.xls"

Of course, the filename parameter can contain path information, but User-Agnet ignores this information and only takes the last part of the path information as the file name. When you use this header message when the response type is application/octet- stream, it means that you don't want to display the content directly, but a "file download" dialog box pops up, and it's up to you to decide whether to "open" or "save".

Note:

1. When Content-Disposition is used in the code to ensure that the browser pops up the download dialog box. Response.addHeader ("Content-Disposition", "p_w_upload"); make sure that nothing has been done to disable browser caching. 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 fine in opera and firefox, but not in IE, but you can't find the file.

In IE5 and Opera, the browser will ignore the contents of the Content-Disposition header. To declare Content-Type again, declare that Content-Length can display the download progress bar.

The code is as follows:

$fileName = 'config.ini';$mimeType =' application/zip';if (strpos ($_ SERVER ['HTTP_USER_AGENT'],' MSIE 5') or strpos ($_ SERVER ['HTTP_USER_AGENT'],' Opera 7')) {$mimeType = 'application/x-download';} header (' Content-Disposition: paired _ HTTP_USER_AGENT'; filename='. $fileName); header ('Content-Type:'. $mimeType); header ('Content-Length:'. Filesize ($fileName))

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report