无法使用codeigniter在数据库表中插入多个图像的路径 [英] Not able to insert path for multiple images in database table using codeigniter

查看:77
本文介绍了无法使用codeigniter在数据库表中插入多个图像的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法弄清楚如何使这多个图像路径上传工作。我已经尝试修复它2天,但没有运气。

I can't seem to figure out how to make this multiple image path upload working. I have been trying to fix it for 2 days but no luck.

问题:当表单提交时,它会将选定数量的图像上传到上传文件夹,但只插入路径对于db表中的一个图像。

Problem: when form is submitted it uploads selected numbers of images to 'upload' folder but only inserts path for one image in db table.

// Form Validation Goes Here
} else {
    // Image upload starts here
    $number_of_files = count($_FILES['uploadedimages']['tmp_name']);
    $files = $_FILES['uploadedimages'];
    for($i=0;$i<$number_of_files;$i++) {
      if($_FILES['uploadedimages']['error'][$i] != 0) {
    $this->form_validation->set_message('fileupload_check', 'At least 1 image needed.');
    return FALSE;
  }
}
    $this->load->library('upload');
    $config['upload_path'] = FCPATH . 'uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = '0';
    $config['overwrite']     = FALSE;
    for ($i = 0; $i < $number_of_files; $i++) {
      $_FILES['uploadedimage']['name'] = $files['name'][$i];
      $_FILES['uploadedimage']['type'] = $files['type'][$i];
      $_FILES['uploadedimage']['tmp_name'] = $files['tmp_name'][$i];
      $_FILES['uploadedimage']['error'] = $files['error'][$i];
      $_FILES['uploadedimage']['size'] = $files['size'][$i];

      $this->upload->initialize($config);
      if ($this->upload->do_upload('uploadedimage')) {
    $data['uploadedimage'] = $this->upload->data();
    $image_name = $data['uploadedimage']['file_name'];
    $data['uploadedimage'] = $image_name;
  } else {
    $this->form_validation->set_message('upload_error', $this->upload->display_errors());
    return FALSE;
  }
}
$this->load->model('admin/model_users');
if($query = $this->model_users->insert_property_details($data)) {
redirect('dashboard/property-successfully-posted');
}

模型是:

        $insert_images = array(
        'property_images' => $data['uploadedimage'],
        'property_ref_id'   => $id,
        );
        $this->db->insert('vbc_property_images', $insert_images);

视图文件中的字段名称为uploadedimage。

And field name in view file is 'uploadedimage'.

<input type="file" name="uploadedimages[]" accept="image/*" multiple />


推荐答案

$ data ['uploadedimage' ($ data ['uploadedimage'] as $ key ==> $ val)loop for read multiple data.and use'property_images'=> $ val for insert data

$data['uploadedimage'] should be in foreach( $data['uploadedimage'] as $key==>$val) loop for read multiple data.and use 'property_images' => $val for insert data

这篇关于无法使用codeigniter在数据库表中插入多个图像的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆