2011-12-03 76 views
1

我的多圖像上傳有問題。Codeigniter多圖像上傳錯誤消息

代碼

function tester($yourUniqueId){ 

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

      for($i=0; $i<count($_FILES); $i++) 
      { 

       $_FILES['userfile']['name'] = $_FILES['filename']['name'][$i]; 
       $_FILES['userfile']['type'] = $_FILES['filename']['type'][$i]; 
       $_FILES['userfile']['tmp_name'] = $_FILES['filename']['tmp_name'][$i]; 
       $_FILES['userfile']['error']  = $_FILES['filename']['error'][$i]; 
       $_FILES['userfile']['size'] = $_FILES['filename']['size'][$i]; 

       $path = './uploads/' . $yourUniqueId; 
       mkdir($path); 

       $config['file_name']  = "kep_" . $i; 
       $config['upload_path'] = $path; 
       $config['allowed_types'] = 'jpg|jpeg|png'; 
       $config['max_size']  = '0'; 
       $config['overwrite']  = FALSE; 

       $this->upload->initialize($config); 

       if($this->upload->do_upload()) 
       { 
       $error += 0; 

       }else{ 
       $error += 1; 
       } 
      } 

       if($error > 0){ 

        return FALSE; 
        }else{ 
         return TRUE; 

        } 



} 

它有點奇怪,因爲,它返回false,我給它的回聲

if($error > 0){ 
echo 'Something went wrong'; //just for a test     
return FALSE; 

犯規它sopose顯示回聲?

我不能讓它工作。

有沒有東西與代碼worng?

可以請別人給我一個提示? 我不能看到它的任何地方

回答

1

嘗試更換此:

if($this->upload->do_upload()) 
{ 
    $error += 0; 
}else{ 
    $error += 1; 
} 

有了這個:

if (!$this->upload->do_upload()) 
{ 
    $error++; 
    echo $this->upload->display_errors(); 
} 

這應該告訴你,哪裏出了問題。你也可能想包裝mkdir()函數,以防目錄確實存在(我不知道PHP如何處理它 - 可能會提前返回):

if (!is_dir($path)) 
{ 
    mkdir($path, 0777, TRUE); // make it writable! 
}