【问题标题】:CodeIgniter Upload multiple filesCodeIgniter 上传多个文件
【发布时间】:2013-04-15 21:22:23
【问题描述】:

控制器

$config['upload_path'] = '../ci/assets/images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024'; 
$config['max_height'] = '768';

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

//load mPhoto model
$this->load->model("carstock_model"); 

//Check to see if upload was activated if/then/else statement
if (! $this->upload->do_upload())
{
    $error = array('error' => $this->upload->display_errors()); 
    $this->load->view('admin_view.php', $error);
} 
else 
{
    for($i=1; $i<6; $i++) {
        $data = array('upload_data' => $this->upload->data()); 
        $data2 = $this->input->post(NULL, TRUE); //returns POST items with XSS filter
        $filename = $data['upload_data']['file_name']; //obtain the upload filename
        $data2['picture' .$i]= $filename .$i; //get and set the filename

        // $data2['PhotoFilenameLarge']=$filename; //get and set the filename
        $this->carstock_model->insertData($data2); //add the db
    }

    $this->load->view('upload_success', $data); //display the success view
}

查看

...    
<input name="userfile" type="file" multiple="multiple" />
...

型号

public function insertData($data){
$this->db->insert("carstock", $data); //active record
}

问题是当在 mysql 中传递文件时,只将最后选择的图像作为输入并存储错误的名称。 感谢您的帮助。

【问题讨论】:

    标签: file codeigniter upload


    【解决方案1】:
    for($i = 0;$i<=2;$i++){
        $name = 'image_0'.$i;
    
        if(isset($_FILES[$name])){
            $this->upload->do_upload($name);
            $data = $this->upload->data();
            dump($data['file_name']);
        }else{
            // do nothing
    } // end of for loop
    

    转储($data['file_name']);将转储文件名。但是您必须为每个字段选择文件

    【讨论】:

      猜你喜欢
      • 2012-01-12
      • 2013-12-05
      • 2015-01-07
      • 1970-01-01
      • 1970-01-01
      • 2012-03-05
      相关资源
      最近更新 更多