Welcome Guest, Not a member yet? Register   Sign In
Upload and resize image problem.
#1

Hello, 
I have the below code and i want to upload and resize the image.

The thing is that even though the inputs are changing the image is not uploaded.. I have the same code in some other functions too but i don't get any errors. Any thoughts on that?

Controller:
Code:
public function update_user_data() {
   if ( $this->session->userdata('logged_in') == true ) {
     $user_id = $this->session->userdata('user_id');

     //Image uploading
     $config = array(
       'upload_path' => './assets/img/users/' . $user_id,
       'encrypt_name' => TRUE,
       'allowed_types' => 'gif|jpg|jpeg|png',
       'max_size' => '2048000',
       'max_width' => '4096',
       'max_height' => '4096'
     );
     $this->load->library('upload', $config);
     $dir_exist = true; //Default flag for dir existence

     if ( !is_dir('./assets/img/users/' . $user_id) ) {
       mkdir('./assets/img/users/' . $user_id, 0777, true);
       $dir_exist = false; // dir not exist
     }
     if ( !$this->upload->do_upload('userfile') ) {
       if(!$dir_exist)
       rmdir('./assets/img/users/' . $user_id);
       $image = '';
     } else {
       $config['image_library'] = 'gd2';
       $config['source_image'] = $this->upload->data('full_path');
       $config['maintain_ratio'] = TRUE;
       $config['width'] = 350;
       $config['height'] = 350;

       $this->load->library('image_lib', $config);
       if ( !$this->image_lib->resize() ){
         echo $this->image_lib->display_errors();
       }
       $data = array('upload_data' => $this->upload->data());
       $image = $this->upload->data('file_name');
     }

     $update = $this->user_model->update_user_data($user_id, $image);

     redirect ('users/' . $user_id);
   }
 }


Model:
Code:
public function update_user_data($user_id, $image){
   //Update contact data
   $contact_data = array();
   $contact_data['primary_num'] = $this->input->post('userNum');
   $contact_data['num_1'] = $this->input->post('userNum2');
   $contact_data['num_2'] = $this->input->post('userNum3');
   $contact_data['num_3'] = $this->input->post('userNum4');

   //User data in array
   $data = array();
   if ($this->input->post('userPassword')) {
     $data['password'] = $this->input->post('userPassword');
   }

   if ( !empty($image) ) {
     $data['user_image'] = $image;
   }

   $data['screen_name'] = $this->input->post('userScreenName');
   $data['about'] = $this->input->post('userAbout');
   $data['website'] = $this->input->post('userSite');
   //Update data
   $this->db->update('contact_info', $contact_data, array('to_user_id' => $user_id));

   return $this->db->update('users', $data, array('user_id' => $user_id));

 }


Even though i've done an extensive search in google i couldn't find anything....

//Life motto
if (sad() == true) {
     sad().stop();
     develop();
}
Reply


Messages In This Thread
Upload and resize image problem. - by HarrysR - 09-08-2018, 12:50 PM
RE: Upload and resize image problem. - by HarrysR - 09-08-2018, 05:04 PM
RE: Upload and resize image problem. - by HarrysR - 09-09-2018, 10:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB