2016-07-12 18 views
0

我在上傳自己的資料圖片和核查目的的文件,用戶需要用戶登記表上工作。這是形式中的兩個不同領域。代碼工作正常,但問題是它只上傳配置文件圖像並將其存儲在驗證文檔文件夾中。它不會上傳驗證文件。如果我刪除或評論其中一個字段,它可以正常工作。上傳多個文檔,PHP笨

以下是我的控制器功能。

/** UPLOAD PROFILE IMAGE **/ 

    $prof_pic = $_FILES['profile_pic']['name']; 

    $config = array ('upload_path' => './images/tutors/', 
        'allowed_types' => "jpeg|jpg|png", 
        'overwrite' => TRUE 
        ); 

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


    /** UPLOAD VERIFICATION DOCUMENT **/ 

    $tut_ver_docs = $_FILES['tut_ver_docs']['name']; 

    $new_config = array ('upload_path' => './emp_verification_documents/', 
         'allowed_types' => "jpeg|jpg|png", 
         'overwrite' => TRUE 
        ); 

    $this->load->library('upload', $new_config); 
    $this->upload->do_upload('tut_ver_docs'); 
+0

哪裏變量'$ Maxtype''$ fname'和'$ lname'? – Kisaragi

+0

$ Maxtype,$ fname和$ lname是我文件中的全局變量..它們不是問題。 –

+0

如果你命名的文件完全一樣,他們是。 – Kisaragi

回答

0

嘗試更換:

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

有:

$this->load->library('upload'); 
$this->upload->initialize($config); 
+0

我應該如何處理$ this-> load-> library('upload',$ new_config); –

+0

只需添加:$ this-> upload-> initialize($ new_config); – Rijin

0

更換

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

$this->upload->initialize($new_config); 
0

我不完全知道爲什麼你加載上傳類兩次:

$this->load->library('upload'); 
$this->upload->upload_path = './images/tutors/'; 
$this->upload->allowed_types = array('jpeg','jpg','png'); 

foreach($_FILES as $name => $file){ 
    if($name == 'tut_ver_docs'){ //if its the verification document, change the upload path 
     $this->upload->upload_path = './emp_verification_documents/'; 
    } 
    if(! $this->upload->do_upload($name){ 
     //catch error 
    } 
} 
0

我沒有測試,但我認爲這應該爲你工作

/** UPLOAD PROFILE IMAGE **/ 
$this->load->library('upload');//load the library 

$config = array ('upload_path' => './images/tutors/', 
       'allowed_types' => "jpeg|jpg|png", 
       'overwrite' => TRUE 
       );//config for profile picture 
$this->upload->initialize($config); 
if (!$this->upload->do_upload('profile_pic')) 
{ 
    print_r($this->upload->display_errors());//upload fails.you can print the error or display somewhere else 
} 


/** UPLOAD VERIFICATION DOCUMENT **/ 

$tut_ver_docs = $_FILES['tut_ver_docs']['name']; 

$new_config = array ('upload_path' => './emp_verification_documents/', 
        'allowed_types' => "jpeg|jpg|png", 
        'overwrite' => TRUE 
       ); 
$this->upload->initialize($new_config); 
if (!$this->upload->do_upload('tut_ver_docs')) 
{ 
    print_r($this->upload->display_errors());//upload fails 
}