• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating file using CI File Upload Library

#1
[eluser]jamesduncan[/eluser]
Hi there,

I've searched the forum and tried to find some info on StackOverflow - but I might not be understanding things correctly.

I have successfully been able to upload files to my server and insert the file path to my my database using The File Uploader Library from the User Guide.

http://ellislab.com/codeigniter/user-gui...ading.html

I'm using Ion Auth for my User Management (thanks for all your help Ben!) so I can also successfully insert the ID of the user that just uploaded the file into the Database.

But I can't figure out how to overwrite the existing file path once the user has uploaded another one.

Basically I'm just trying to build out a User Profile Image upload form - so I might be doing this all completely backward - but learning a lot in the process - so all good.

Here is my do_load function from the user guide mixed in with some Ion Auth code - the file is uploading ok - Im getting a success confirmation and the path is getting written to my database table - I now need to be able to tell if the user already has a profile image and over-write the existing one with a newly uploaded one - let know if any one needs to see any other code from me.

Thanks!

Code:
function do_upload()
{
  $user = $this->ion_auth->user()->row();
  //$user_id = $this->ion_auth->user()->row('id');
  
  //$user = $this->ion_auth->user()->row();
  //echo $user->id;
  //'userid' => $userid['userid'],
  $config['upload_path'] = './gs-assets/uploads/';
  $config['allowed_types'] = 'gif|jpg|jpeg|png';
  $config['max_size'] = '100';
  $config['max_width']  = '1024';
  $config['max_height']  = '768';

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

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

   $this->load->view('upload_form', $error);
  }
  else
  {
   $image_data = $this->upload->data();
  
   $insert_data = array(
      //'id' => $this->ion_auth->user()->row('id'),
      //'id' => $user,
      'id' => $user->id,
                    'name' => $image_data['file_name'],
                    'path' => $image_data['full_path'],
                    //'thumb_path'=> $image_data['file_path'] . 'thumbs/'. $image_data['file_name'],
                    //'tag' => $tag
                     );
            
           $this->db->insert('profile_photos', $insert_data);//load array to database
  
   $data = array('upload_data' => $this->upload->data());
   $this->load->view('upload_success', $data);
  }
}



Messages In This Thread
Updating file using CI File Upload Library - by El Forum - 08-08-2012, 08:39 AM
Updating file using CI File Upload Library - by El Forum - 08-08-2012, 11:29 AM
Updating file using CI File Upload Library - by El Forum - 08-08-2012, 11:40 AM
Updating file using CI File Upload Library - by El Forum - 08-08-2012, 12:16 PM
Updating file using CI File Upload Library - by El Forum - 08-08-2012, 12:43 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.