2016-09-26 65 views
-4
public function upload($file = array(), $where) 
{ 
    if (file_exists($this->src.$file['name'])) 
    { 
     $data['error'] = "Sorry, file already exists."; 
    } 
    elseif ($file["name"]["size"] > 500000) { 
     $data['error'] = "Sorry, your file is too large."; 
    } 
    elseif(is_array($file)) 
    { 
     if(in_array($file['type'], $this->type)) 
     { 
      $filePath = $this->src.$file['name']; 
      $file_Check = move_uploaded_file($file['name']['tmp_name'], $filePath); 
      if ($file_Check) 
      { 
       print_r($file); die(); 
       $name = $file['name']; 
       //$this->update(array('photo'=>$name,'candi_id'=>$where)); 
      }    
      $data['error'] = 'File has been uploaded'; 
     } 
     else 
     { 
      $data['error'] = 'File formet was not supported'; 
     } 
    } 
    else 
    { 
     $data['error'] = 'No File was uploaded...';   
    } 

    return $data;  
} 

輸出:文件上傳在哎呀PHP不工作

文件路徑顯示正確。函數也工作正常,但文件不移動到文件夾?

+0

您檢查您的文件夾的權限? – Dharmendra

+0

考慮fomatting。這是不可讀的。 – abksrv

+0

得到這個正確的? '$ filePath' ??哪個錯誤'$ data ['error']'你會得到什麼? – devpro

回答

0

添加enctype="multipart/form-data"到您的形式,像

<form enctype="multipart/form-data" > 
<input name="file" type="file"> 
... 
</form>