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

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!