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"
<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>
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <div class="modal-body">

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

        <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">


And this my controller file Corsi.php:

    defined('BASEPATH') OR exit('No direct script access allowed');  
    class Corsi extends CI_Controller {  
        public function __Construct() {
            $this->load->helper(array('form', 'url'));
            if(!$this->session->userdata('logged_in')) {
        function index(){  
            $data["title"] = "Lista Corsi"; 
            $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')) {
            } else {   

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题