codeigniter Ошибка загрузки изображения - PullRequest
0 голосов
/ 28 августа 2018
public function getbasicinfo()
{
    if($this->form_validation->run('basicinfo')==TRUE) {
      $data=$this->input->post();

       $config = [
                'upload_path'   => 'assets/img/jobseeker',
                'allowed_types' => 'gif|jpg|png',
                'max_size'      => '10000',
                'max_width'     => '1024',
                'max_height'    => '768',
                'overwrite'     =>  TRUE,
               'encrypt_name'  =>  FALSE,
                'remove_spaces' =>  TRUE
        ];

        if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
        $this->load->library('upload', $config);

        if(! $this->upload->do_upload('image'))
        {
            $error = $this->upload->display_errors();
            $this->session->set_flashdata('image',$error);
                redirect('Jobseeker_profile/editbasicinfo');
        }
        $img = $this->upload->data();
        $data['image']=$img['file_name'].$id;
        $this->load->model('jobseeker_profilemodel','profile');              
        $query=$this->profile->basicinfo($data);
        if ($query==TRUE) {
            redirect('jobseeker/jobpreference');
        }

    }else{
        $this->load->view('jobseeker/editBasicInfoMyProfile');
   }    
}

при загрузке изображения с использованием вышеуказанного метода выдает следующую ошибку

Неустранимая ошибка: необученная ошибка: вызов функции-члена do_upload () для null в C: \ xampp \ htdocs \ Project \ application \ controllers \ Jobseeker_profile.php: 53 Трассировка стека: # 0 C: \ xampp \ htdocs \ Проект \ system \ core \ CodeIgniter.php (360): Jobseeker_profile-> getbasicinfo () # 1 C: \ xampp \ htdocs \ Project \ index.php (202): require_once ('C: \ xampp \ htdocs ...' ) # 2 {main} в C: \ xampp \ htdocs \ Project \ application \ controllers \ Jobseeker_profile.php в строке 53

1 Ответ

0 голосов
/ 28 августа 2018

Вы пропустили do_upload определение функции и здесь исправлен код

Вот пример кода HTML

<html>
    <head>
    <title>Upload Form</title>
    </head>
    <body>

        <?php echo form_open_multipart('upload/do_upload');?>

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

            <br /><br />

            <input type="submit" value="upload" />

        </form>

    </body>
</html>

Вот пример кода PHP для загрузки изображения

 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())
        {
            $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);
        }
    }

Вот структура примера класса для функции do_upload, думаю, это поможет вам понять определение функции do_upload

class Upload extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }

    function index()
    {
        $this->load->view('upload_form', array('error' => ' ' ));
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...