2016-09-26 122 views
1

我有一个窗体,实现字段上传超过1个文件。但我仍然困惑如何将它存储到MySQL。我只想将所有文件保存在MySQL中,只需提交一次。我需要你的帮助。如何在codeigniter中保存文件上传的文件名

这是我的控制器:

function do_upload() { 
     $config['upload_path'] = './uploads/'; 
     $config['allowed_types'] = 'jpeg|png|gif|jpg|txt|docs'; 
     $config['max_size'] = '2000'; 
     $config['max_width'] = '2000'; 
     $config['max_height'] = '2000'; 

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

     foreach ($_FILES as $key => $value) { 

      if (!empty($value['tmp_name'])) { 

       if (! $this->upload->do_upload($key)) { 
        $error = array('error' => $this->upload->display_errors()); 
       } else { 
       } 
      } 
     } 
} 

,这是我的看法:

<?php echo form_open_multipart('upload/do_upload');?> 
<input type="file" name="file1" /> 
<input type="file" name="file2"/> 
<input type="file" name="file3"/> 
</div> 
<br /><br/> 
<input type="submit" value="upload" name="upload" /> 
</form> 

回答

0

当上传成功,返回一些数据。

看一看这里:CI3 Docs

因此,将其保存到一个变量,说$data一样,

$data = $this->upload->do_upload($key); 

这将是一个数组,并获得上传的文件名与$data['file_name']。这将在你的代码的其他条件。