2015-07-21 53 views
1

我試圖使用codeigniter文件上傳庫上傳多個圖像,但它只上傳一個文件,即使選擇了多個文件。請協助Codeigniter只上傳一個圖像而不是多個

//uploading images 
    public function upload_image() { 
     $this->load->helper('form'); 

     $config = array(
      'upload_path' => "./image_uploads/", 
      'allowed_types' => "jpg|png|jpeg", 
      'overwrite' => TRUE, 
      'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb) 
      'max_height' => "768", 
      'max_width' => "1024" 
     ); 
     $this->load->library('upload', $config); 

     var_dump($_FILES); die(); 

     foreach ($_FILES as $key => $userfileObject) { 
      if (!empty($userfileObject['name'])) { 
       $this->upload->initialize($config); 
        var_dump($_FILES['userfile']); 
       if (!$this->upload->do_upload($_FILES[$key])) { 
        $errors = $this->upload->display_errors(); 
        flashMsg($errors); 
       } else { 
        // Code After Files Upload Success GOES HERE 
        $data['content'] = 'success'; 
        $this->load->view('templates/template', $data); 
       }`enter code here` 
      } 
     } 

    } 
+0

是「菊花」 – Kabs

+0

我上傳不同的文件名如文件。 '沙漠'和'菊花',它選擇了最後一個......我怎麼去解決它...? – Kabs

回答

0

這可能幫助其中p_image是文件名

if (isset($_FILES['p_image']['name'])) { 
       // total files // 
       $count = count($_FILES['p_image']['name']); 
       // all uploads // 
       $uploads = $_FILES['p_image']; 

       for ($i = 0; $i < $count; $i++) { 
        if ($uploads['error'][$i] == 0) { 
         move_uploaded_file($uploads['tmp_name'][$i], 'uploads/product_cover/' . $uploads['name'][$i]); 

        } 
       } 
      } 
0
foreach($_FILES as $key => $userfileObject) 
      { 

       if ($this->upload->do_upload($key)) 
       { 
        $errors = $this->upload->display_errors(); 
        flashMsg($errors); 
       } 
       else { 
       // Code After Files Upload Success GOES HERE 
       $data['content'] = 'success'; 
       $this->load->view('templates/template', $data); 
       }`enter code here` 


      } 
相關問題