skip to Main Content

The image name is getting saved in the database but the image is not getting saved in the file manager, is there any permission problem in the file manager of cpanel or coding issue?

Controller

function addprofilepicture()
{
    $userID = $this->session->userdata("user_id");
    $data['user'] = $this->m_user->getRows($userID);
    $config['upload_path']          = './assets/Images/profilepictures';
    $config['allowed_types']        = 'gif|jpg|png|jpeg';

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload('userfile')){
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    } else {
        $image = $_FILES['userfile']['name'];
        $this->m_user->update_pic($image);
    }
}

Model

public function update_pic ($image){
    if($this->session->userdata("user_id"))//If already logged in
    {
        $userID = $this->session->userdata("user_id");
        $data['user'] = $this->m_user->getRows($userID);
        $data = array('profile_pic' => $image,);

        $this->db->where('user_id', $userID);
        return $this->db->update('users', $data);
    }
}

View

<?php echo form_open_multipart('user/addprofilepicture'); ?>   
<input type="file" name="userfile" size="20" required>
<input type="submit" class="btn btn-primary" value="Upload" />

<?php echo form_close(); ?>

2

Answers


  1. Better use full path, that is if your assets is in the root directory (where the main index.php is)

    ./ signifies current directory where upload is being executed

    $config['upload_path']          = FCPATH.'assets/Images/profilepictures';
    
    Login or Signup to reply.
  2. You can use

    function addprofilepicture()  {
       $userID = $this->session->userdata("user_id");
       $data['user'] = $this->m_user->getRows($userID);
       $config['upload_path'] = './assets/Images/profilepictures/';
       $config['allowed_types'] = 'gif|jpg|png';       
       $this->upload->initialize($config);
       $this->load->library('upload', $config);
       if ( ! $this->upload->do_upload('userfile')){
        $error = array('error' => $this->upload->display_errors());    
        $this->load->view('upload_form', $error);
        } else {
        $image = $_FILES['userfile']['name'];
        $this->m_user->update_pic($image);
           }
          }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search