示例:

<?php
function delete_file($path){
    if(is_dir($path)){
        if($res = opendir($path)){
            while($file=readdir($res)){
                if($file != '.' && $file != '..'){            
                    if(is_file($path.'/'.$file)){
                        unlink($path.'/'.$file);
                    }else if(is_dir($path.'/'.$file)){
                        delete_file($path.'/'.$file);
                    }
                }
            }
            closedir($res);
            rmdir($path);
        }
    }else if(is_file($path)){
        unlink($path);
    }
}

相关函数:

unlink() 函数删除文件。
rmdir() 函数删除空的目录。


 

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2021-11-20
  • 2021-11-23
  • 2021-05-16
  • 2021-05-16
  • 2021-09-27
猜你喜欢
  • 2022-01-24
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2021-06-03
  • 2021-09-20
相关资源
相似解决方案