Jump to content
Sign in to follow this  
westman

delete_directory

Recommended Posts

Hi all,
I am working with some old script to remove files and folders.
 

$directory = "../pics/$id";
function delete_directory($directory, $empty=false)
{
  if(substr($directory,-1) == DIRECTORY_SEPARATOR){
    $directory = substr($directory,0,-1);  }
  
  if(!is_dir($directory) || !is_readable($directory)){
    return false;  }
  
  else{
    $handle = opendir($directory);
    while (false !== ($item = readdir($handle))){
      if($item != '.' && $item != '..'){
        $path = $directory.DIRECTORY_SEPARATOR.$item;
        if(is_dir($path)){
          delete_directory($path);	}
        
		else{
          unlink($path);
        }
      }
    }
    closedir($handle);
 
    if($empty == false){
      if(!rmdir($directory)){
        return false;	}
    }
    return true;	}
}	
delete_directory($directory);

Will this still work in the new php version?

Share this post


Link to post
Share on other sites

Can you test it in a new version?  It's the best way to find out.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×