2016-10-21 102 views
-2

我有一個同名的輸入字段。 pdf [] 我插入並上傳到數據庫它完全插入數據庫。但沒有上傳到上傳文件夾沒有與do_upload();PDF文件不上傳

$items=$_FILES['pdf']['name']; 
    $count = count($items); 
    $lstid=$this->FetchData->getLastInserted(); 
    for($i=0; $i<=$count-1; $i++){ 
     //echo $img[$i]; 
     $img = $_FILES['pdf']['name'][$i]; 
     $timezone = new DateTimeZone('Asia/Calcutta'); 
     $datetime = new DateTime("now", $timezone); 
     $date = $datetime->format("D_M_d_Y_H_i_s"); 
     $ext = pathinfo($img, PATHINFO_EXTENSION); 
     $new_name=$i.'_'.$state_id.'_'.$date; 
     if(!empty($img)){ 
     $imagenamefordatabase = $new_name.'.'.$ext; 
     } 
     else{ 
     $imagenamefordatabase =''; 
     } 
     $config['upload_path'] = 'uploads/'; 
     // set the filter image types 
     $config['allowed_types'] = 'pdf'; 
     $config['file_name'] = $new_name; 
     //load the upload library 
     $this->load->library('upload', $config); 
     $this->upload->initialize($config); 
     $this->upload->set_allowed_types('*'); 
     $data['upload_data'] = ''; 
     //if not successful, set the error message 
     if (!$this->upload->do_upload('pdf[]')) { 
     $data = array('Success' => $this->upload->display_errors()); 
     } 
     else { 
     //else, set the success message 
     $data = array('Success' => "Upload success!"); 
     $data['upload_data'] = $this->upload->data(); 
     } 
     $sampleresult = array(
     'Report_Print_Data_Id' => $lstid, 

     'Sample_Report' => $imagenamefordatabase 
    ); 

     $this->AddData->addReportResult($sampleresult); 
    } 
+0

請分享'$ this-> upload-> do_upload'方法定義。 –

+0

@ jeroen這是我的正確代碼。我必須上傳多個文件與輸入名稱相同。 __pdf [] __我得到擴展名,因爲用不同的名字保存文件。在我使用代碼Igniter的上傳庫之後。然後將名稱保存到MySQL數據庫中。 – devendra

+0

@NareshKumarNakka $ this-> upload-> do_upload()是codeigniter默認庫。 – devendra

回答

0

變化的問題提交的名稱爲userfile的。

在控制器中配置文件大小並嘗試。

如果有任何錯誤請顯示。

+0

謝謝您的回覆。我通過解答了答案。爲循環聲明上面的變量。 __files = $ _ FILE; __ and for for循環__ $ _FILES ['pdf'] ['name'] = $ files ['pdf'] ['name'] [$ i]; __ and do_upload('pdf'); – devendra

0

你必須通過字段名稱只有沒有大括號[]。更新您的代碼的以下部分。

if (!$this->upload->do_upload('pdf')) { 
    $data = array('Success' => $this->upload->display_errors()); 
} 
else 
{ 
    //else, set the success message 
    $data = array('Success' => "Upload success!"); 
    $data['upload_data'] = $this->upload->data(); 
} 
+0

謝謝。我解決了這個問題。我會回覆答案 – devendra