user3071261
user3071261

Reputation: 386

send image path to database codeigniter

I try to upload a file and send the image path to codeigniter. But I always get this error:

A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant full_path - assumed 'full_path'
Filename: controllers/Story.php
Line Number: 22
Backtrace:
File: /Applications/MAMP/htdocs/VERSIE0.1/application/controllers/Story.php
Line: 22
Function: _error_handler
File: /Applications/MAMP/htdocs/VERSIE0.1/index.php
Line: 292
Function: require_once

Does anybody know a solution?

my code:

if ($this->input->server('REQUEST_METHOD') == 'POST') {
        $config['upload_path'] = '../images/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '1000000';
        $config['overwrite'] = TRUE;
        $config['remove_spaces'] = TRUE;
        $config['encrypt_name'] = FALSE;

        $this->load->library('upload', $config);
        $this->upload->do_upload('story_img');
        $image_path = $this->upload->data();
        $story_img = $image_path[full_path];

        echo var_dump($story_img);

        $story_text = $this->input->post("story_text");
        $users_id = $this->input->post('users_id');


        $this->form_validation->set_rules('story_text', 'Story text', 'required');
        $this->form_validation->set_rules('story_img', 'Story image ', 'callback__image_upload');
        if ($this->form_validation->run() != FALSE) {

            $new_story = new Story_model();
            $new_story->Story_text = $story_text;
            $new_story->Users_id = $users_id;
            $new_story->Story_date = date('Y-m-d H:i:s');
            $new_story->Story_img = $story_img;


            $this->Story_model->addStory($new_story);
        }
    }

Upvotes: 0

Views: 435

Answers (1)

Mureinik
Mureinik

Reputation: 311088

Full path should be a string literal, not a bareword:

$story_img = $image_path['full_path'];

Upvotes: 4

Related Questions