多表单上传:在codeigniter中分别获取每个文件名

Multiple form upload: get each file name separately in codeigniter

我想上传一些文件。我使用 codeigniter:

Html:

<input type="file" name="file1" />
<input type="file" name="file2" />

php:

$config['upload_path'] = './upload/';
$path = $config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['encrypt_name'] = 'TRUE';
$this->load->library('upload', $config);

foreach ($_FILES as $key => $value) {
        if (!empty($value['tmp_name']) && $value['size'] > 0) {
            if (!$this->upload->do_upload($key)) {
               // some errors
            } else {
                // Code After Files Upload Success GOES HERE
                $data_name = $this->upload->data();
                echo $data_name['file_name'];
            }
        }
    }

当我想要 echo 文件名时,我得到 1.jpg2.jpg。但是我想把它们分开并插入到数据库中。

我该怎么做?谢谢:)

$data_name['file_name'] 中的值添加到数组中,然后在 foreach 循环后执行 insert_batch.

类似于:

$filename_arr = array();
foreach ($_FILES as $key => $value) {
        if (!empty($value['tmp_name']) && $value['size'] > 0) {
            if (!$this->upload->do_upload($key)) {
               // some errors
            } else {
                // Code After Files Upload Success GOES HERE
                $data_name = $this->upload->data();
                $filename_arr[] = $data_name['file_name'];
            }
        }
    }

$this->db->insert_batch('mytable', $filename_arr);