本文整理汇总了PHP中filesystem::delete_files方法的典型用法代码示例。如果您正苦于以下问题:PHP filesystem::delete_files方法的具体用法?PHP filesystem::delete_files怎么用?PHP filesystem::delete_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类filesystem
的用法示例。
在下文中一共展示了filesystem::delete_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete_files
/**
* Delete Files
*
* Deletes all files and optionally folders from the path specfied
*
* @param string path to file
* @param bool delete contained directories
* @param bool delete root directory (this is the same as a recursive delete_all - use with caution!)
* @return void
*/
public static function delete_files($path, $mask = NULL, $del_dir = FALSE, $del_root = FALSE, $level = 0)
{
// Trim the trailing slash
$path = preg_replace('|/+$|', '', $path);
// fail if a leading slash is encountered
if ($level == 0 && preg_match('%^[\\\\/]+%', $path)) {
trigger_error('filesystem::deletefiles - <span style="color:red">Absolute paths not allowed</span>', E_USER_WARNING);
return;
}
// fail on directory error
if (!($current_dir = @opendir($path))) {
return;
}
// file mask
if ($level == 0 && $mask != NULL) {
// regular expression for detecing a regular expression
$rxIsRegExp = '/^([%|\\/]|{).+(\\1|})[imsxeADSUXJu]*$/';
// an array of file extenstions
if (is_array($mask)) {
$mask = '%\\.(' . implode('|', $mask) . ')$%';
} else {
if (!preg_match($rxIsRegExp, $mask)) {
$mask = "/\\.{$mask}\$/";
}
}
}
// loop through files
while (FALSE !== ($filename = @readdir($current_dir))) {
if ($filename != "." and $filename != "..") {
if (is_dir($path . '/' . $filename)) {
filesystem::delete_files($path . '/' . $filename, $mask, $del_dir, $del_root, $level + 1);
} else {
if ($mask == NULL || preg_match($mask, $filename)) {
unlink($path . '/' . $filename);
}
}
}
}
@closedir($current_dir);
// remove folders
if ($del_dir && $level > 0) {
@rmdir($path);
}
if ($del_root && $level == 0) {
@rmdir($path);
}
}