我尝试上传文件并将图片路径发送到codeigniter。但我总是得到这个错误:
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
有人知道解决方案吗?
我的代码:
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);
}
}
答案 0 :(得分:4)
完整路径应该是字符串文字,而不是赤字:
$story_img = $image_path['full_path'];