《PHP學習:php刪除指定目錄的方法》要點:
本文介紹了PHP學習:php刪除指定目錄的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP編程本文實例講述了php刪除指定目錄的辦法.分享給大家供大家參考.具體分析如下:
PHP編程這段代碼可實現(xiàn)遞歸刪除子目錄的功能
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程序設計有所贊助.
歡迎參與《PHP學習:php刪除指定目錄的方法》討論,分享您的想法,維易PHP學院為您提供專業(yè)教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/11119.html