我有一個同名的輸入字段。 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);
}
請分享'$ this-> upload-> do_upload'方法定義。 –
@ jeroen這是我的正確代碼。我必須上傳多個文件與輸入名稱相同。 __pdf [] __我得到擴展名,因爲用不同的名字保存文件。在我使用代碼Igniter的上傳庫之後。然後將名稱保存到MySQL數據庫中。 – devendra
@NareshKumarNakka $ this-> upload-> do_upload()是codeigniter默認庫。 – devendra