2016-07-12 12 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 
}