2016-12-16 143 views
-1

我試圖將兩個不同字段的兩種不同類型的文件發佈到我的數據庫中。我一直在尋找整個Stack Overvlow的答案,但我仍然無法找到它。使用CodeIgniter上傳多個文件

這是我的控制器:

public function insertLamaran() 
{ 
$pas_foto = ($_FILES['pas_foto']['name']); 
$cv = ($_FILES['cv']['name']); 
if ($pas_foto !== "") 
{ 
    $config['upload_path'] = './uploads/'; 
    $config['log_threshold'] = 1; 
    $config['allowed_types'] = 'jpg|png|jpeg|gif'; 
    $config['max_size'] = '100000'; // 0 = no file size limit 
    $config['file_name']='smallImage.jpg'; 
    $config['overwrite'] = false; 
    $this->load->library('upload', $config); 
    $this->upload->do_upload('pas_foto'); 
    $upload_data = $this->upload->data(); 
    $data['pas_foto'] = $upload_data['file_name']; 
    } 

    if ($cv !== "") 
    { 
        $config['file_name']='bigImage.pdf'; 
        $config['upload_path'] = './uploads/'; 
        $config['allowed_types'] = 'pdf'; 
        $config['max_size'] = '100000'; // 0 = no file size limit 
        $config['overwrite'] = false; 
        $this->load->library('upload', $config); 
        $this->upload->do_upload('filename1'); 
        $upload_data = $this->upload->data(); 
        $data['cv'] = $upload_data['file_name']; 
    } 

    $data['u_id'] = $this->input->post('u_id'); 
    $this->M_upload->insertLamaran($data); 
} 

,這是我的看法:

<form action="<?php echo base_url('Upload/insertLamaran')?>" method="post"> 
    <input hidden type="text" name="u_id" value="<?php echo ucfirst($this->session->userdata('u_id')); ?>"></input><br> 
    <div class="row wowload fadeInLeftBig"> 
     <div class="col-sm-6 col-sm-offset-3 col-xs-12"> 
     <label for="pasfoto">Pas Foto (.jpg)</label> 
     <input id="pas_foto" type="file" name="pas_foto" multiple="true"> 
     <label for="CV">CV (.pdf)</label> 
     <input id="cv" type="file" name="cv" multiple="true"> 
     <button class="btn btn-primary"><i class="fa fa-paper-plane"></i> Send</button> 
     </div> 
    </div> 
    </form 

錯誤說

未定義指數:pas_foto。文件名:controllers/Upload.php行號:22

有沒有人知道發生了什麼,我該如何解決?

回答

0

,因爲我看到你正確的形式類型,以便回答pdf文件 你忘了添加PDF文件名

改變這種

$this->upload->do_upload('filename1'); 

這個

$this->upload->do_upload('cv'); 
0

首先,在您的控制器的constructor中加載url幫手。我認爲你的視圖文件必須是這樣的。需要將enctype="multipart/form-data"用於文件上傳。

<form action="<?php echo base_url('upload/insertLamaran');?>" method="post" enctype='multipart/form-data'> 
    <input hidden type="text" name="u_id" value="<?php echo ucfirst($this->session->userdata('u_id')); ?>"></input><br> 
    <div class="row wowload fadeInLeftBig"> 
     <div class="col-sm-6 col-sm-offset-3 col-xs-12"> 
     <label for="pasfoto">Pas Foto (.jpg)</label> 
     <input id="pas_foto" type="file" name="pas_foto" multiple="true"> 
     <label for="CV">CV (.pdf)</label> 
     <input id="cv" type="file" name="cv" multiple="true"> 
     <button class="btn btn-primary" type="submit"><i class="fa fa-paper-plane"></i> Send</button> 
     </div> 
    </div> 
</form> 
+0

謝謝, maaas!但現在,問題是..只有成功上傳的圖像..不是PDF .. –