首页 > Web开发 > 详细

php删除指定目录的方法

时间:2015-12-31 22:30:49      阅读:266      评论:0      收藏:0      [点我收藏+]

本文实例讲述了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程序设计有所帮助。

php删除指定目录的方法

原文:http://www.jb51.net/article/63441.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!