php 檔案上傳有關問題

來源:互聯網
上載者:User
php 檔案下載問題
PHP code
function download_file($filename){     //below to provide the download                    if (file_exists($filename)) {                                                 $file = fopen($filename);                    header('Content-Description: File Transfer');                    header('Content-Type: application/octet-stream');                    header('Content-Disposition: attachment; filename=' . basename($filename));                    header('Content-Transfer-Encoding: binary');                    header('Expires: 0');                    header('Cache-Control: must-revalidate');                    header('Pragma: public');                    header('Content-Length: ' . filesize($filename) . ' bytes');                    //ob_clean();                    //flush();                    readfile($filename);                    fclose($file);                       exit;}$this->_redirect('xxxxxxx');




以上是網上通用的一段php檔案下載的代碼,我的問題是這樣的,我要實現點擊一個button實現下載同時實現重新整理頁面的內容嗎,也就是說我不希望 exit;我在檔案下載了之後還要繼續執行之後的代碼。也就是說我的下載完成之後$this->_redirect('xxxxxxx');這個語句不執行,請教下有什麼解決方案嗎?

------解決方案--------------------

$file = fopen($filename);
readfile($filename);
fclose($file);
直接readfile就行了。


這個重新導向只能用JS做了, 但onclick只能標記一下變數, 等失去焦點檢查一下變數再說.


C/C++ code
[User:root Time:23:25:51 Path:/home/apache/web]$ cat index.html aaa
------解決方案--------------------
不可以,一個HTTP會話只能傳遞一種類型的資料
況且下載對使用者而言是非同步
------解決方案--------------------
開啟而不是儲存,這是因為檔案類型瀏覽器能夠識別,比如chrome會顯示pdf檔案,而不是儲存。
你需要額外添加一個Header回應標頭:
Content-Disposition: attachment; filename="$檔案名稱"

至於如何添加,你可以讓PHP來讀取輸出這個產生的檔案,並用header函數即可。
或者web伺服器也可以配置對檔案強制下載,不過我不知道怎麼設定
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.