Codeigniter - 插入并重命名上传图像文件以自动增加ID

时间:2016-11-19 03:38:16

标签: php mysql sql codeigniter

我尝试重命名上传图片(3张图片),然后插入mysql。 问题是,$this->db->insert_id();必须在插入查询之后放置,$config['file_name']必须在上传之前放置。 我应该如何重命名为auto-id然后上传和插入?

                $config['upload_path']          = 'images/location';
                $config['allowed_types']        = 'gif|jpg|png';
                $config['max_size']             = 2048; //2048KB = 2MB
                $config['max_width']            = 2000;
                $config['max_height']           = 1500;



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

                $this->upload->do_upload('userfile'); 
                $data_upl['image1'] = $this->upload->data('file_name');

                $this->upload->do_upload('userfile2');
                $data_upl['image2'] = $this->upload->data('file_name');

                $this->upload->do_upload('userfile3');
                $data_upl['image3'] = $this->upload->data('file_name');

                $data = array(
                   'location_pic' => $data_upl['image1'],
                   'location_pic2' => $data_upl['image2'],
                   'location_pic3' => $data_upl['image3']
                );

                $this->db->insert('oav_event', $data);

                $get_id = $this->db->insert_id();
                $config['file_name'] = "id".$get_id;

                $this->load->view('admin/success', $data_upl);

0 个答案:

没有答案