How to whole remove dir in php

phpasks

New Member
Messages
145
Reaction score
0
Points
0
I have below proble problem when remove whole dir.



it keeps giving me this PHP error :
Warning: rmdir(../../infusions/theme_database/temp/f8e0c65c0461b6631aa83234f20c9011//themes/DarkZik/forum) [function.rmdir]: Directory not empty in /home/themes/public_html/infusions/theme_database/theme_submission_inc.php on line 15

Cheer
Asif Khalyani
 

scorch94

Member
Messages
228
Reaction score
0
Points
16
Clearly, you've got to run a loop to delete all the files in directory previously :)
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
here is something small and fast you can use.

PHP:
function delete_directory($dirname) {
  if (is_dir($dirname)){
    $dir_handle = opendir($dirname);
  }
  if (!$dir_handle){
    return false;
  }
  while($file = readdir($dir_handle)) {
    if ($file != "." && $file != "..") {
      if (!is_dir($dirname."/".$file)){
        unlink($dirname."/".$file);
      }else{
        delete_directory($dirname.'/'.$file);
      }
    }
   closedir($dir_handle);
   rmdir($dirname);
  return true;
}

always worth a shot. Not sure if it works because I just googled that
 

phpasks

New Member
Messages
145
Reaction score
0
Points
0
I know this recrusive function through delete whole directory.

Any other command to direct remove whole dir.

Any one knows only one command through delete whole dir.

here is something small and fast you can use.

PHP:
function delete_directory($dirname) {
  if (is_dir($dirname)){
    $dir_handle = opendir($dirname);
  }
  if (!$dir_handle){
    return false;
  }
  while($file = readdir($dir_handle)) {
    if ($file != "." && $file != "..") {
      if (!is_dir($dirname."/".$file)){
        unlink($dirname."/".$file);
      }else{
        delete_directory($dirname.'/'.$file);
      }
    }
   closedir($dir_handle);
   rmdir($dirname);
  return true;
}
always worth a shot. Not sure if it works because I just googled that
 

KSclans

New Member
Messages
197
Reaction score
0
Points
0
it say on line 15 do you find any problem in line 15 ? I need more info...
 
Top