我希望上传内容保存到项目目录中的upload/images文件夹中,但不是。上传保存到数据库目录时,上传/图像文件夹为空
public function addArticleForm(){
//check whether user upload picture
if(!empty($_FILES['image_path']['upload_path'])){
$config['upload_path'] = 'uploads/images/';
$config['allowed_types'] = 'jpg|jpeg|png|gif|';
$config['file_name'] = $_FILES['image_path']['upload_path'];
//load upload library and initialize configuration
$this->load->library('upload',$config);
$this->upload->initialize($config);
if($this->upload->do_upload('image_path')){
$uploadData = $this->upload->data();
$image_path = $uploadData['file_name'];
}else{
$image_path = '';
}
}
尝试设置图像上传的动态功能
public function upload_images($path,$filename){
$config = array(
'upload_path' => $path,
'allowed_types' => "gif|jpg|png|jpeg",
'overwrite' => TRUE,
'max_size' => "204800", // 20 mb
);
$this->load->library('upload', $config);
$this->upload->initialize($config);
if($this->upload->do_upload($filename)){
$upload_data = $this->upload->data();
$datas = array('file_name' => $upload_data['file_name'], 'file_size'=>$upload_data['file_size'], 'file_type'=>$upload_data['file_type']);
$file_name = $upload_data['file_name'];
$file_size = $upload_data['file_size'];
$file_type = $upload_data['file_type'];
} else {
$datas = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error_msg',$datas['error']);
}
return $datas;
}
并在另一个函数中使用上述函数,如
public function Add_Customer_Profiles(){
if($this->session->userdata('userid')!="" || null!==$this->session->userdata('userid')){
$custno = $this->input->post('custno',TRUE);
$fname = $this->input->post('fname',TRUE);
$lname = $this->input->post('lname',TRUE);
$email = $this->input->post('email',TRUE);
$mobile = $this->input->post('mobile',TRUE);
$path = './assets/profile_data/';
$img_name = 'customer_img'; // Your file input name
$file_detail = $this->upload_images($path,$img_name);
if(!isset($file_detail['error'])){
//Your Code here
}
}
public function addArticleForm(){
$config['upload_path'] = "./backend/images/";
$config['allowed_types'] = 'gif|jpeg|png|jpg';
$this->path = './backend/images/';
$this->load->library('upload',$config);
$this->upload->initialize($config);
if (!$this->upload->do_upload('file_name'))
{
$error = array('error'=>$this->upload->display_errors());
}else{
$dataUpload = $this->upload->data();
//echo $dataUpload['file_name'];
}
$data = array(
'name'=>$this->input->post('name'),
'image'=>$dataUpload['file_name'],
'created_by'=>$this->input->post('created_by'));
$insertdata = $this->db->insert('table_name',$data);
}