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/".$item, TRUE, 1);
delete_files(FCPATH."assets/img/users/covers/".$item, TRUE, 1);
delete_files(FCPATH."assets/img/users/status/".$item, TRUE, 1);
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