Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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将数据上载到数据库_Php_Database_Codeigniter - Fatal编程技术网

Php 如何使用codeigniter将数据上载到数据库

Php 如何使用codeigniter将数据上载到数据库,php,database,codeigniter,Php,Database,Codeigniter,我想使用codeigniter将图像上传到数据库。它保存到数据库,但图像没有发送到我设置的文件夹路径,只有图像路径保存到数据库。你能告诉我该做什么或者我做错了什么吗?这是我的密码: *控制器* function saveEvent(){ $config = [ 'upload_path' => './assets/img', 'allowed_types' => 'gif|png|jpg|jppeg'

我想使用codeigniter将图像上传到数据库。它保存到数据库,但图像没有发送到我设置的文件夹路径,只有图像路径保存到数据库。你能告诉我该做什么或者我做错了什么吗?这是我的密码:

*控制器*


function saveEvent(){

        $config = [
            'upload_path' => './assets/img',
            'allowed_types' => 'gif|png|jpg|jppeg'
        ];

        $this->load->library('upload', $config);
        $this->form_validation->set_error_delimiters();
        $this->upload->do_upload();
        // var_dump('asd'. $this->upload->do_upload());
        // if($this->upload->do_upload()){
            $datas = $this->input->post('eventimage');
            $info = $this->upload->data();
            $image_path = "./assets/img/".$info['raw_name'].$info['file_ext'];
            $data['cal_events_image'] = $image_path;
            $data['cal_events_name'] = $this->input->post('eventname');
            unset($data['submit']);
            $this->load->model('CalendarModel');
            if($this->CalendarModel->eventinsertdata($data)){
                echo "success";
            }else{
                echo " fail";
            }


<form action="<?php echo base_url('index.php/CalendarController/saveEvent');?>" enctype="multipart/form-data" method="post" accept-charset="utf-8">
                <table class="table">
                    <tr>
                        <td>Event Type</td>
                        <td><input type="text" name="eventname"></td> 
                    </tr>
                    <tr>
                        <td>Image</td>
                        <td><input type="file" name="eventimage"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submitevent" value="Add Event" class="btn btn-success"></td>
                    </tr>
                </table>
            </form>

function eventinsertdata($data){
return $this->db->insert('table', $data);
     return $this->db->insert('dev_adkt_events_type', $data);
        echo 'hahay';

    }

*查看*


function saveEvent(){

        $config = [
            'upload_path' => './assets/img',
            'allowed_types' => 'gif|png|jpg|jppeg'
        ];

        $this->load->library('upload', $config);
        $this->form_validation->set_error_delimiters();
        $this->upload->do_upload();
        // var_dump('asd'. $this->upload->do_upload());
        // if($this->upload->do_upload()){
            $datas = $this->input->post('eventimage');
            $info = $this->upload->data();
            $image_path = "./assets/img/".$info['raw_name'].$info['file_ext'];
            $data['cal_events_image'] = $image_path;
            $data['cal_events_name'] = $this->input->post('eventname');
            unset($data['submit']);
            $this->load->model('CalendarModel');
            if($this->CalendarModel->eventinsertdata($data)){
                echo "success";
            }else{
                echo " fail";
            }


<form action="<?php echo base_url('index.php/CalendarController/saveEvent');?>" enctype="multipart/form-data" method="post" accept-charset="utf-8">
                <table class="table">
                    <tr>
                        <td>Event Type</td>
                        <td><input type="text" name="eventname"></td> 
                    </tr>
                    <tr>
                        <td>Image</td>
                        <td><input type="file" name="eventimage"></td>
                    </tr>
                    <tr>
                        <td colspan="2"><input type="submit" name="submitevent" value="Add Event" class="btn btn-success"></td>
                    </tr>
                </table>
            </form>

function eventinsertdata($data){
return $this->db->insert('table', $data);
     return $this->db->insert('dev_adkt_events_type', $data);
        echo 'hahay';

    }


提前谢谢你们。希望你能帮我解决这个问题。

我已经解决了!这是我的答案,它是有效的

控制器


首先,尝试使用此代码检查错误
if($this->upload->do_upload()){//Coding…}否则{print_r($this->upload->display_errors());}
。还有什么可以得到的error@DanishAli您好,先生,我将更新我的代码,并稍微更改我的问题。但是谢谢你,先生。@DanishAli这真的帮了大忙。非常感谢。然后接受答案并投票