php删除指定目录的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了php删除指定目录的方法。分享给大家供大家参考。具体分析如下:

这段代码可实现递归删除子目录的功能

<?php
/**
 * Delete a file, or a folder and its contents 
 * (recursive algorithm)
 * @author Aidan Lister <aidan@php.net>
 * @version 1.0.3
 * @param string  $dirname Directory to delete
 * @return bool Returns TRUE on success, FALSE on failure
 */
function rmdirr($dirname)
{
 // Sanity check
 if (!file_exists($dirname)) {
  return false;
 }
 // Simple delete for a file
 if (is_file($dirname) || is_link($dirname)) {
  return unlink($dirname);
 }
 // Loop through the folder
 $dir = dir($dirname);
 while (false !== $entry = $dir->read()) {
  // Skip pointers
  if ($entry == '.' || $entry == '..') {
   continue;
  }
  // Recurse
  rmdirr($dirname . DIRECTORY_SEPARATOR . $entry);
 }
 // Clean up
 $dir->close();
 return rmdir($dirname);
}
?>

希望本文所述对大家的php程序设计有所帮助。

相关文章

浅谈htmlentities 、htmlspecialchars、addslashes的使用方法

1、html_entity_decode():把html实体转换为字符。 Eg:$str = "just atest & 'learn to use '"...

php读取html并截取字符串的简单代码

复制代码 代码如下:<?php $title='【宜配屋www.yipeiwu.com】'; $hello='jb51.net!'; $file=file_get_contents...

php无限极分类递归排序实现方法

本文实例讲述了php无限极分类递归排序实现方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:function order ($array,$pid=0){  ...

PHP API接口必备之输出json格式数据示例代码

前言 我们在日常的开发工作中免不了要写接口,json格式文本的输出是制作接口必须掌握的,现在通行的接口基本是采用json格式的数据。下面话不多说,来看看本文的详细内容: 简单的php&n...

php采集内容中带有图片地址的远程图片并保存的方法

本文实例讲述了php采集内容中带有图片地址的远程图片并保存的方法。分享给大家供大家参考。具体实现方法如下: 复制代码 代码如下:function my_file_get_contents...