简体   繁体   中英

Images not saving to temporary folder only saved to Database

I want uploads to save to upload/images folder in my project directory but it is not. The upload/images folder is empty while the upload saves to database directory

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 = '';
        }

}

Try This for setting up a dynamic function for image upload

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;
}

And use above function in another function, Like

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);
        
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM