2016-09-26 125 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']。這將在你的代碼的其他條件。