1

i've been trying to delete folder and the files in it. The code return no error but the folder is not removed. I am sure the path is correct. What do i miss ?

  function delete_avatar($id) {
             $dir = base_url()."assets/uploads/Avatar/".$id; 

            foreach(glob($dir . '/*') as $file) { 
            if(is_dir($file)) rrmdir($file); else unlink($file); 
            } rmdir($dir); 
    }
highcal
  • 73
  • 1
  • 11
  • Did you define `rrmdir` function? PHP doesn't have it. – Invis1ble Mar 24 '17 at 02:11
  • Possible duplicate of [How do I recursively delete a directory and its entire contents (files + sub dirs) in PHP?](http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir) – Invis1ble Mar 24 '17 at 02:12
  • Use FCPATH instead of base_url() for removal of files or directories. –  Mar 24 '17 at 03:06

1 Answers1

0

rmdir not rrmidr

        foreach(glob($dir . '/*') as $file) { 
        if(is_dir($file)) rmdir($file); else unlink($file); 
        } rmdir($dir); 
}
layouteam
  • 51
  • 6