写了一个 文件下载的程序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才可以的

解决方案 »

  1.   

    在一个action中调用 我在里面做的内容就是查找下内容 然后生成一个文件 然后就是这个提供下载的功能,这个功能之后 就是一些数据库的操作 然后进行一个页面的刷新
      

  2.   

    这样呢:if(download_file($filename)){
      #下面的操作
    }else{
      #错误提示
    }
      

  3.   

    你就改为return false;或者直接去掉不加return会怎样?对你后来有无影响
      

  4.   


    我去掉return 也已经试过了 不能够提供下载。
      

  5.   

    不太明白你说的 你说的也是将return给省略了吗? return省略去了 我也不可以运行
      

  6.   


    嗯 按照你 的想法 我试了一下 还是不行,我理解了一下我的这个错误似乎是这样的的,因为我的这段代码是放在一个action中,好像只有我跳出了这个action才能够进行下载。比如说我不用函数调用了 我直接将下载的代码粘贴进我的action中 return true还留下,这样的话在下载的时候跳出这个action 下载也是可以执行的。
      

  7.   

    你那个函数return false就相当于preventDefault不会提交表单
    在满足答件时,例如检查字段为非空,然后return true;页面才进行跳转,也才会调用你的action
    这是表单提交常用的阻止异常提交的方法
      

  8.   


    下载功能算是一个表单吗?而且我的return true不是可以执行吗?