Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter:Filename';不显示在数据库上_Php_Codeigniter - Fatal编程技术网

Php Codeigniter:Filename';不显示在数据库上

Php Codeigniter:Filename';不显示在数据库上,php,codeigniter,Php,Codeigniter,我只是学习将图像数据保存到数据库中,它们是文件名和路径。该路径显示在数据库上,但不带文件名。有什么问题吗 这是控制器 function do_upload() { $config['upload_path']='./uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['

我只是学习将图像数据保存到数据库中,它们是文件名和路径。该路径显示在数据库上,但不带文件名。有什么问题吗

这是控制器

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);
    $this->upload_model->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);
    }
}
模型呢

    function upload ($config) {
    $config = $this->upload->data();
    $upload_data = array(
        'path' => $config['full_path'],
        'nama_foto' => $config['file_name']
    );

    $this->db->insert('tb_picture', $upload_data);
}
桌子呢

我该怎么办


之前谢谢您。

在阅读本文之前,请您自己再试一次,或者尝试网络上的任何一种viedotutorial

控制器功能应如下所示

function do_upload()
    {
        $config['upload_path']='./uploads/'; //needs to set uploads folder CHMOD 0644
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';

        $config['overwrite']  = FALSE;
        $config['remove_spaces']  = TRUE;

        $field_name = "userfile"; //name tag in our HTML form in case you want to change it

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload($field_name)) //upload happens
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }    
        else
        {
             //succesful upload get data from upload and use them with our model
             $upload_data = $this->upload->data();
             $this->upload_model->upload($upload_data);
        }
    }    
型号功能

function upload ($data) {

    if (empty($data) || $data === FALSE) return FALSE;

    $insert_data = array(
        'path' => $data['full_path'],
        'nama_foto' => $data['file_name']
    );

   $this->db->insert('tb_picture', $insert_data);

   return $this->db->insert_id(); //returns last inserted ID
}

请注意,您的模型完全“错误”,您在其中使用了上载功能,请尝试仅向模型传递
数据,以便模型可以处理它。

阅读此文章之前,请您自己重试,或尝试web上的任何类型的viedotutorial

控制器功能应如下所示

function do_upload()
    {
        $config['upload_path']='./uploads/'; //needs to set uploads folder CHMOD 0644
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '100';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';

        $config['overwrite']  = FALSE;
        $config['remove_spaces']  = TRUE;

        $field_name = "userfile"; //name tag in our HTML form in case you want to change it

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload($field_name)) //upload happens
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
        }    
        else
        {
             //succesful upload get data from upload and use them with our model
             $upload_data = $this->upload->data();
             $this->upload_model->upload($upload_data);
        }
    }    
型号功能

function upload ($data) {

    if (empty($data) || $data === FALSE) return FALSE;

    $insert_data = array(
        'path' => $data['full_path'],
        'nama_foto' => $data['file_name']
    );

   $this->db->insert('tb_picture', $insert_data);

   return $this->db->insert_id(); //returns last inserted ID
}

请注意,您的模型完全“错误”了,您在其中使用了上载功能,请尝试仅向模型传递
数据
,以便模型可以处理它。

尝试执行
变量转储($config)
以检查该数组中的实际内容。@Nana Puspita请按顺序逐行阅读您的代码,您的
$config
变量是否具有属性
[完整路径]
?嗯,我想不会,因为您在实际文件上载之前将其插入数据库。请尝试执行
var\u dump($config)
检查该数组中的实际内容。@Nana Puspita请按顺序逐行阅读您的代码,您的
$config
变量是否具有属性
[full\u path]
?嗯,我想不会,因为你们在实际上传文件之前就把它插入数据库了。谢谢你们的回答。。这完全是真的。还有链接,真的很感兴趣。非常感谢你的回答。。这完全是真的。还有链接,真的很感兴趣。非常感谢你。