试图在codeigniter中的一列中上传两个图像filepath


trying to upload two images file_path in one column in codeigniter

我试图在一列中上传两个图像file_path。在我的模型中,我成功地从$filepath获得了第一个图像路径,但$a不起作用,我也很困惑$a是否获得了我的第二个图像路径

请帮我

提前谢谢。

我的控制器

<?php
class upload extends CI_Controller {
    function __construct()
    {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
    }
    function index()
    {
        $this->load->view("main_temp/header.php");
        $this->load->view('post_ad_views', array('error' => ' ' ));
        $this->load->view("main_temp/footer.php");
    }
// controller
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';
    $config['file_name'] = $new_file_name;
    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view("main_temp/header.php");
        $this->load->view('post_ad_views', $error);
        $this->load->view("main_temp/footer.php");
    }
    else
    {
        // success
        $data = array('upload_data' => $this->upload->data());
        // a model that deals with your image data (you have to create this)
        $this->load->model('submit_ad_model');
        $this->submit_ad_model->ad_post();
        $this->load->view('upload_success', $data);

   }

}
}
?>

车型年款

<?php
class submit_ad_model extends CI_Model
{
    function ad_post()
    { 
        $filepath = $this->upload->data()['file_name']; 
         $a = $this->upload->data()['file_name']; 
        $this->db->query("insert into ads (ad_pic)  values ('$filepath,$a')");
?>

我的视图

<input type="file" name="userfile" class="upload image"  id="userfile" />
<input type="file" name="userfile2" class="upload image"  id="userfile" />

您不想获得第二个上传的项目,您需要使用一个循环:

       $upload_data = array();
       foreach($_FILES as $key => $value){
           $this->upload->do_upload($key);
           $upload_data[$key] = $this->upload->data($key);
        }
         $this->submit_ad_model->ad_post($upload_data);