Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法使用codeigniter下载文件_Php_Codeigniter - Fatal编程技术网

Php 无法使用codeigniter下载文件

Php 无法使用codeigniter下载文件,php,codeigniter,Php,Codeigniter,这是我的下装载机控制器。第一次它工作正常。它打开“另存为”弹出窗口,可以下载所需文件,但下一次它将显示直接目录列表 <?php class Download extends Controller { function Download(){ parent::Controller(); $this->load->helper('download'); echo "I am in constructor"; } function index(){ $f

这是我的下装载机控制器。第一次它工作正常。它打开“另存为”弹出窗口,可以下载所需文件,但下一次它将显示直接目录列表

<?php

class Download extends Controller {

 function Download(){
  parent::Controller();
  $this->load->helper('download');
  echo "I am in constructor";

 }

 function index(){
  $file = realpath("download")."\\profile.doc"; 
  echo "I am in index.";

        exit;

  if (file_exists($file)) {
      header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename=' . basename($file));
            header('Content-Transfer-Encoding: binary');
            header('Expires: 0');
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            ob_clean();
            flush();
            readfile($file);
            exit;
        }else{

   // File Not Found

         echo "File not found";
        }

 }
}
?>



您应该使用下载帮助程序,如中所示。它处理这种情况。

您应该使用下载帮助程序,如中所示。它处理这种情况。

您的URL在“第一次”和“第二次”尝试之间如何变化?了解CodeIgniter有自己的下载帮助程序可能会很有用,这正是您的需求-下次是什么意思?再次单击同一页面上的下载链接后?您的URL在“第一次”和“第二次”之间如何变化?了解CodeIgniter有自己的下载帮助程序可能会很有用,这正是您的需求-下次是什么意思?再次单击同一页面的下载链接后?