duandou8120 2018-09-17 13:53
浏览 92
已采纳

CodeIgniter 3 - 上传文件错误:未定义属性/在null上调用成员函数

I have a problem with codeigniter when I try to send a file. The page returns me the following error:

Error page file upload codeigniter 3

This is my bootstrap modal in file view scadenze.php:

<div class="modal fade" id="uploadFile" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
 aria-hidden="true">
<div class="modal-dialog">
    <div class="modal-content">

        <?php echo form_open_multipart('corsi/upload_file');?>

        <div class="modal-header modal-blue">
            <h4 class="modal-title" id="myModalLabel">Carica File<br>
                <span id="corso" style="font-size: 14px;color: #888;"></span><span id="utente" style="font-size: 14px;color: #888;"></span>
            </h4>
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        </div>
        <div class="modal-body">

        <input type="file" name="userfile" size="20" />

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Annulla</button>

            <input id="uploadFileSubmit" type="submit" class="btn btn-primary" value="upload">

        </div>
    </form>
    </div>
</div>

And this my controller file Corsi.php:

<?php  
    ob_start();
    defined('BASEPATH') OR exit('No direct script access allowed');  
    class Corsi extends CI_Controller {  
        public function __Construct() {
            parent::__Construct();
            $this->load->helper(array('form', 'url'));
            if(!$this->session->userdata('logged_in')) {
                redirect(base_url());
            }
            $this->load->model('corsi_model');
        }
        //functions  
        function index(){  
            $data["title"] = "Lista Corsi"; 
            $this->load->view('frame/header_view');
            $this->load->view('frame/sidebar_nav_view');
            $this->load->view('corsi/index', $data);  
        }

        public function upload_file() {   
            $this->load->helper(array('form', 'url'));
            $config['upload_path']   = './uploads/attestati/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']      = 2048000;
            $config['max_width']     = 1024;
            $config['max_height']    = 768;

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

            // check if folder exists
            if( ! is_dir($config['upload_path'])) {
                @mkdir($config['upload_path'], 0777, true);
            }
            if ( ! $this->corsi->upload_file('userfile')) {
                $this->load->view('frame/header_view');
                $this->load->view('frame/sidebar_nav_view');
                $this->load->view('corsi/creaclasse');
            } else {   
                $this->load->view('frame/header_view');
                $this->load->view('frame/sidebar_nav_view');
                $this->load->view('corsi/creaclasse');
            }
        }
    }

Someone is able to understand where I'm wrong? Thx.. and sorry for my bad English.

  • 写回答

2条回答 默认 最新

  • dpda53918 2018-09-17 14:25
    关注

    In your function for upload_file you write:

    $this->corsi->upload_file('userfile')
    

    Which should be:

    $this->upload->do_upload('userfile')
    


    Your error message is telling you that it can't find the property corsi within the instance of $this.

    Please make sure to check CodeIgniters Documentation for their file upload library which can be found here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问1553 RT怎么测试,没有BC有方法吗
  • ¥100 业务编程如何选择学习方向和内容?
  • ¥15 wamp3.3.5安装完成后图标正常显示绿色,鼠标左右键点击图标均无反应。求解决方法。
  • ¥15 鼠标点击的这条记录了什么?
  • ¥15 在写pid调速的程序时,电机始终维持最大速度
  • ¥15 【有偿】调用DXGI截图初始化失败,提示0xf 887a0004
  • ¥15 请问如何查看手机root记录?
  • ¥15 商城小程序订单号重复
  • ¥15 学校优化算法sbo和蚁群算法怎么结合
  • ¥21 matlab怎么求时域信号的二阶导数