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 手机连接电脑热点显示无ip分配
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大