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);                    return true;                }else{                    echo("the file not exist");                    return false;                }                //above to provide the download }

但是沒有進行 下載的功能。檔案在上一步已經產生了。 但是如果我將 return true改成exit 下載功能可以實現,但是檔案下載之後我還要進行其他的功能。請教大神們這是怎麼回事? 我看網上的下載例子也不是說需要exit才可以的


------解決方案--------------------
看你在哪調用這個函數,檢查下在哪裡調用的,那裡是不是有問題?
------解決方案--------------------
這樣呢:
PHP code
if(download_file($filename)){  #下面的操作}else{  #錯誤提示}
------解決方案--------------------
探討
寫了一個 檔案下載的程式PHP code
function download_file($filename){
//below to provide the download
if (file_exists($filename)) {

$file ……

------解決方案--------------------
探討

引用:

這樣呢:
PHP code

if(download_file($filename)){
#下面的操作
}else{
#錯誤提示
}



不太明白你說的 你說的也是將return給省略了嗎? return省略去了 我也不可以運行

------解決方案--------------------
你那個函數return false就相當於preventDefault不會提交表單
在滿足答件時,例如檢查欄位為非空,然後return true;頁面才進行跳轉,也才會調用你的action
這是表單提交常用的阻止異常提交的方法
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.