php - 将图像路径发送到数据库 codeigniter

标签 php mysql image codeigniter upload

我尝试上传文件并将图像路径发送到 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);
        }
    }

最佳答案

完整路径应该是字符串文字,而不是裸词:

$story_img = $image_path['full_path'];

关于php - 将图像路径发送到数据库 codeigniter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29849050/

相关文章:

php - mysql中设计关系

PHP: Datetime::Diff 结果比较

sql - 我将如何在 Rails 中执行此 JOIN 操作?

java - 如何在mysql表中保存货币符号unicode

python - 查看 .npy 图像

image - grep 删除 WordPress 'crunched' 文件

php - 带有键的数组的 Twig for 循环

php - 如何将 Controller 放入 Laravel 5.1.3 的文件夹中?

mysql - CentOS 上的 Plesk MySQL 驱动程序配置错误

android - 使用从 URL 下载的图像在主屏幕上创建快捷方式