【问题标题】:Multiple Image upload in array Codeigniter数组Codeigniter中的多个图像上传
【发布时间】:2016-11-12 13:36:30
【问题描述】:

大家晚上好,我的代码有问题。我正在做一个带有单独字段的画廊表单。

我总是以“无”输出结束,因为即使我在 thumbnails[] 字段中输入了一些内容,它也没有得到我的输入。

任何人都知道我该如何解决它以及如何完成它。非常感谢。

这是我的 html 代码:

Main Image:
<input type="file" name="file1" required/> 
Thumbnails:
<input type="file" name="thumbnails[]"  />
<input type="file" name="thumbnails[]"  />
<input type="file" name="thumbnails[]"  />

在我的控制器中:

    $config = array(
    'upload_path' => "./uploads/workplace/",
    'allowed_types' => "jpg|png|jpeg",
    'remove_spaces' => TRUE,
    'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
    'max_height' => "0",
    'max_width' => "0"
    );
    $this->load->library('upload', $config);
    if($this->upload->do_upload('file1'))
    {
      $config = array(
      'upload_path' => "./uploads/workplace/",
      'allowed_types' => "jpg|png|jpeg",
      'remove_spaces' => TRUE,
      'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
      'max_height' => "0",
      'max_width' => "0"
      );
      $this->load->library('upload', $config);            
      if($this->upload->do_upload('thumbnails[]'))  
      {
        echo "yea";
      } 
      else
      {
        echo "none";
      }
    }

【问题讨论】:

    标签: php codeigniter file-upload


    【解决方案1】:
     $config = array(
    'upload_path' => "./uploads/workplace/", 
    'allowed_types' => "jpg|png|jpeg",
    'remove_spaces' => TRUE,
    'max_size' => "2048000", // Can be set to particular file size , here it is                 2 MB(2048 Kb)
    'max_height' => "0",
    'max_width' => "0"
    );
    $this->load->library('upload', $config);
    
     foreach ($_FILES as $key) {
    
            if (!$this->upload->do_upload($key)) {
                 echo $this->image_lib->display_errors();
            }else
            {
                 echo "<strong>Your Thumb image has been successfully Uploded..!!</strong><br><br>";
            }
        }
    

    【讨论】:

      【解决方案2】:

      试试这个代码。

             $count = count($_FILES['filename']['size']);
             //echo "<pre>"; print_r($_FILES);
             foreach($_FILES as $key=>$value)
             for($s=0; $s<=$count-1; $s++)
             {
             $_FILES['userfile']['name']=$value['name'][$s];
             $_FILES['userfile']['type']    = $value['type'][$s];
             $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
             $_FILES['userfile']['error']       = $value['error'][$s];
             $_FILES['userfile']['size']    = $value['size'][$s];
             $config['upload_path'] = './acontrol/document/';
             $config['allowed_types'] = 'gif|jpg|png|pdf';
             $this->load->library('upload', $config);
             $this->upload->initialize($config);
             $this->upload->do_upload();
             $data = $this->upload->data();
             //echo "<pre>"; print_r($this->upload->data());//die;
             $file_rename=str_replace(".","_",$data['file_name']);
             $names='acontrol/document/'.$data['file_name'];
      
             if($data['file_name']!=""){
                  $data=array(
                      'fol5_id'=>$this->input->post('fol5_id'),
                      'doc_file'=>$names,
                      'doc_size'=>$value['size'][$s],
                      'delete_status'=>"NO"
                  );
                  //echo "<pre>"; print_r($data);die;
                  $this->model->insertData("dms_client_doc",$data);
                }
             }
      

      【讨论】:

      • 添加一些解释,说明此答案如何帮助 OP 解决当前问题
      猜你喜欢
      • 2012-12-06
      • 2020-07-10
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2018-09-13
      相关资源
      最近更新 更多