Welcome Guest, Not a member yet? Register   Sign In
How to delete folder according to username.
#1

(This post was last modified: 07-03-2018, 07:17 AM by kirasiris.)

I have a register form in which users can registers to create their own account in my application and I'm giving them the oportunity to upload their own pictures etc. Everything works well so far.
The problem comes when the user and/or admin deletes an user account. For example I as an admin, I decide to delete Brian's account, all of his folders should be deleted as well.

This is the current path:

assets/img/users/avatars/brian
assets/img/users/covers/brian
assets/img/users/status/brian

the naming of the folder by username works great but when deleting the account instead of just deleting his/her folders(whether is within avatars/covers/status), it deletes the whole path, resulting on this(notice there are not avatar/covers/status folders now):

assets/img/users/

This is what I have in my model:
PHP Code:
   public function delete($id)
 
   {
 
       $this->db->where('id'$id);
 
       $this->db->delete($this->table);

 
       // If users closes his account, all of his folders should be deleted as well
 
       $item $this->get($id)->username;
 
       delete_files(FCPATH."assets/img/users/avatars/".$itemTRUE1);
 
       delete_files(FCPATH."assets/img/users/covers/".$itemTRUE1);
 
       delete_files(FCPATH."assets/img/users/status/".$itemTRUE1);
 
       rmdir("assets/img/users/avatars/".$item);
 
       rmdir("assets/img/users/covers/".$item);
 
       rmdir("assets/img/users/status/".$item);
 
   

I hope someone can  help me.

Thanks in advance.
I do Front-End development most of the time 
Reply


Messages In This Thread
How to delete folder according to username. - by kirasiris - 07-03-2018, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB