【问题标题】:download file are not working in codeigniter下载文件在codeigniter中不起作用
【发布时间】:2021-05-16 19:02:41
【问题描述】:

我尝试了不同的方法,但它不起作用。

 function download($id)
{
    $this->load->helper('download');
    $fileinfo = $this->profile_model->download($id);
    $file = 'uploads/'.$fileinfo['file_name'];
    force_download($file, NULL);
    

 }   



   public function do_upload()
    {
            $config['upload_path']          = './uploads/';
            $config['allowed_types']        = 'gif|jpg|png';
            $config['max_size']             = 100;
            $config['max_width']            = 1024;
            $config['max_height']           = 768;

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload('userfile'))
            {
                    $error = array('error' => $this->upload->display_errors());

                    $this->load->view('upload_form', $error);
            }
            else
            {
                    $data = array('upload_data' => $this->upload->data());

                    $this->load->view('upload_success', $data);
            }
    }   


  }
?>

profilemodel.php

 public function download($id)
     {
          $query = $this->db->get_where('upload_cv',array('id'=>$id));
          return $query->row_array();
       }

遇到 PHP 错误 严重性:通知

消息:未定义的属性:Profile_controller::$profile_model

文件名:控制器/profile_controller.php

行号:137

回溯:

文件: E:\xampp\htdocs\jobportal\application\controllers\profile_controller.php 行:137 函数:_error_handler

文件:E:\xampp\htdocs\jobportal\index.php 行:315 功能: 需要一次。

遇到 PHP 错误 严重性:错误

消息:在 null 上调用成员函数 download()

文件名:控制器/profile_controller.php

行号:137

回溯:

【问题讨论】:

    标签: codeigniter codeigniter-3


    【解决方案1】:

    错误提示

    未定义属性:Profile_controller::$profile_model

    这意味着您在控制器中使用 Profile_controller $this->$profile_model 或者没有加载模型:

    $this->load->model('Profile_model');
    

    或函数 load()、类或文件名不以大写的 P 开头。

    因此,您会遇到第二个错误

    在 null 上调用成员函数 download()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多