簡體   English   中英

php下載文件

[英]php downloading files

我需要提供一個jQuery移動應用程序中的文件列表(在台式機和移動設備上都運行)。 主要是從桌面上,我需要從列表中下載文件。 我有一個簡單的href如下:

<a href="download.php?file=test.txt">test.txt<a>

問題是,當用戶單擊鏈接時,將顯示文件的實際內容。 我希望用戶能夠在本地保存文件。 我相信我正確設置了標題。 這是標頭的Firebug轉儲:

Response Headers
Accept-Ranges   bytes
Cache-Control   public, must-revalidate, post-check=0, pre-check=0
Connection  Keep-Alive
Content-Disposition attachment; filename="test.txt"
Content-Length  95
Content-Type    application/octet-stream
Date    Mon, 25 Mar 2013 17:35:26 GMT
Expires -1
Keep-Alive  timeout=5, max=99
Pragma  public
Server  Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/1.0.0-fips
Request Headers
Accept  text/html, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cookie  PHPSESSID=bbf2549f793aed8565b44d532a3088dc; path=%2F; fileDownload=true
Host    192.168.1.225
Referer http://192.168.1.225/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0
X-Requested-With    XMLHttpRequest

我正在從Windows盒子上的瀏覽器進行測試。

我在這里想念什么?

答案比較簡單。 jQuery mobile使所有鏈接成為Ajax請求(我已經忘記了)。 解決方案是在鏈接中添加“ rel =“ external”,以使其成為非ajax鏈接,如下所示:

<a href="download.php?file=test.txt" rel="external">test.txt<a>

感謝Alvaro G. Vicario向我指出正確的方向。

您也可以在jQuet Mobile之前添加此代碼,它對我有用。

<script>
 $(document).bind("mobileinit", function(){
     $.mobile.ajaxEnabled = false;
 }); 
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM