超碰中文网,91久久精品日日躁夜夜躁欧美,一区二区三区精品道,一区二区国产在线观看,亚洲精品中文字幕乱码一区二区,天天看片高清影视在线观看,久久99精品久久久久蜜桃,久久成人影视

VPS參考測評推薦
專注分享VPS主機優惠信息
衡天云優惠活動
熱網互聯2026年促銷活動
hostkvm優惠促銷活動
zji優惠促銷活動
QQGNET優惠促銷活動
QQGNET優惠促銷活動

Content-disposition

主機參考:VPS測評參考推薦/專注分享VPS服務器優惠信息!若您是商家可以在本站進行投稿,查看詳情!此外我們還提供軟文收錄、PayPal代付、廣告贊助等服務,查看詳情!
我們發布的部分優惠活動文章可能存在時效性,購買時建議在本站搜索商家名稱可查看相關文章充分了解該商家!若非中文頁面可使用Edge瀏覽器同步翻譯!PayPal代付/收錄合作

Content-disposition 是 MIME 協議的擴展,MIME 協議指示 MIME 用戶代理如何顯示附加的文件。當 Internet Explorer 接收到頭時,它會激活文件下載對話框,它的文件名框自動填充了頭中指定的文件名。(請注意,這是設計導致的;無法使用此功能將文檔保存到用戶的計算機上,而不向用戶詢問保存位置。)??

??????? 服務端向客戶端游覽器發送文件時,如果是瀏覽器支持的文件類型,一般會默認使用瀏覽器打開,比如txt、jpg等,會直接在瀏覽器中顯示,如果需要提示用戶保存,就要利用Content-Disposition進行一下處理,關鍵在于一定要加上p_w_upload:

Response.AppendHeader("Content-Disposition","p_w_upload;filename=FileName.txt");

備注:這樣瀏覽器會提示保存還是打開,即使選擇打開,也會使用相關聯的程序比如記事本打開,而不是IE直接打開了。

Content-Disposition就是當用戶想把請求所得的內容存為一個文件的時候提供一個默認的文件名。具體的定義如下:

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” “=” ed-string

disp-extension-token = token

disp-extension-parm = token “=” ( token | ed-string )

那么由上可知具體的例子:

Content-Disposition: p_w_upload; filename=“filename.xls”

?????? 當然filename參數可以包含路徑信息,但User-Agnet會忽略掉這些信息,只會把路徑信息的最后一部分做為文件名。當你在響應類型為application/octet- stream情況下使用了這個頭信息的話,那就意味著你不想直接顯示內容,而是彈出一個”文件下載”的對話框,接下來就是由你來決定“打開”還是“保存” 了。

注意事項:

1.當代碼里面使用Content-Disposition來確保瀏覽器彈出下載對話框的時候。 response.addHeader("Content-Disposition","p_w_upload");一定要確保沒有做過關于禁止瀏覽器緩存的操作。如下:

response.setHeader("Pragma", "No-cache");??response.setHeader("Cache-Control", "No-cache");??response.setDateHeader("Expires", 0);

不然會發現下載功能在opera和firefox里面好好的沒問題,在IE下面就是不行,就是找不到文件。

在IE5和Opera中瀏覽器會不管Content-Disposition頭的內容,要再次聲明Content-Type,聲明Content-Length可以顯示下載進度條

代碼如下:

$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:?p_w_upload;?filename='?.?$fileName);

header('Content-Type:?'?.?$mimeType);

header('Content-Length:?'?.?filesize($fileName));


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 filename box automatically fills in the filename specified in the header. (note that this is due to the design; you cannot use this feature to save documents to the user's computer without asking the user for the save location.) ??

When the server sends files to the client browser, if the file type is supported by the browser, it will be opened by the browser by default, such as TXT, JPG, etc., and will be displayed directly in the browser. If the user needs to be prompted to save, it is necessary to use Content-Disposition for processing. The key is to add p w upload:

Response.AppendHeader("Content-Disposition","p_w_upload;filename=FileName.txt");

Note: in this way, the browser will prompt whether to save or open. Even if you choose to open it, you will also use the associated program such as Notepad to open it instead of ie directly.

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:

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” “=” ed-string

disp-extension-token = token

disp-extension-parm = token “=” ( token | ed-string )

Then we can see specific exles from the above:

Content-Disposition: p_w_upload; filename=“filename.xls”

Of course, the filename parameter can contain path information, but user agnet will ignore this information and only use the last part of the path information as the filename. When you use this header when the response type is application / octet stream, it means that you don't want to display the content directly, but pop up a "file download" dialog box, and then you decide whether to "open" or "save".

matters needing attention:

1. When content disposition is used in the code to ensure that the download dialog box pops up. Response.addheader ("content disposition", "P" Upload "); make sure that no action has been taken to disable browser caching. As follows:

response.setHeader("Pragma", "No-cache");??response.setHeader("Cache-Control", "No-cache");??response.setDateHeader("Expires", 0);

Otherwise, it will be found that the download function is OK in opera and Firefox. It's not OK under ie, I just can't find the file.

In IE5 and opera, the browser will ignore the content of the content disposition header. To declare the content type again, declaring the 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:?p_w_upload;?filename='?.?$fileName);

header('Content-Type:?'?.?$mimeType);

header('Content-Length:?'?.?filesize($fileName));

--------------------------------------------------------------
主機參考,收集國內外VPS,VPS測評,主機測評,云服務器,虛擬主機,獨立服務器,國內外服務器,高性價比建站主機相關優惠信息@m.k2270.com
詳細介紹和測評國外VPS主機,云服務器,國外服務器,國外主機的相關優惠信息,商家背景,網絡帶寬等等,也是目前國內最好的主機云服務器VPS參考測評資訊優惠信息分享平臺

這幾篇文章你可能也喜歡:

本文由主機參考刊發,轉載請注明:Content-disposition http://m.k2270.com/12496.html

【騰訊云】領8888元采購禮包,搶爆款云服務器 每月 9元起,個人開發者加享折上折!
打賞
轉載請注明原文鏈接:主機參考 » Content-disposition
主機參考僅做資料收集,不對商家任何信息及交易做信用擔保,購買前請注意風險,有交易糾紛請自行解決!請查閱:特別聲明

相關推薦

評論 搶沙發

評論前必須登錄!