**这是我的整个代码并将图像插入1个表和其他表中的其他数据使用Codeigniter中的最后一个插入ID 1表单
Create.php(
这是视图文件)
<?= form_open('Packages/save') ?>
<label>Package Name:</label><?= form_input('name') ?><br>
<label>Package Name:</label><?= form_input('price') ?><br>
<label>Descriptione:</label><?= form_textarea('description') ?><br>
<label>Image 1:</label><?= form_upload('image1') ?><br>
<label>Image 2:</label><?= form_upload('image2') ?><br>
<label>Image 3:</label><?= form_upload('image3') ?><br>
<?= form_submit('', 'Create Package')?>
<?= form_close()?>
Packages.php(这是控制器)
function save()
{
$this->package->create($this->input->post());
redirect('packages/');
}
function image_upload(){
$config = array(
'upload_path' => "/Images/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
);
$lst_id=$this->package->create($this->input->post());
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$image_data = array(
'id'=> $lst_id,
'upload_data' => $this->upload->data());
$this->load->view('upload_success',$image_data);
}
$this->package->create($this->input->post());
}
Package.php(这是模特)
function create($post)
{
$this->db->insert($this->table, $post);
return $this->db->insert_id();
}
function upload($image_data){
$this->db->insert('images', $image_data);
}