/** * Removes a directory recursively * @param string $dir Directory path * @return int Number of files and folders removed */ function cot_rmdir($dir) { if (empty($dir) && $dir != '0') { return false; } static $cnt = 0; if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $f) { $path = $dir . DIRECTORY_SEPARATOR . $f; if ($f != "." && $f != "..") { if (filetype($path) == "dir") { cot_rmdir($path); } else { unlink($path); $cnt++; } } } reset($objects); rmdir($dir); $cnt++; } return $cnt; }
/** * Removes a directory recursively * @param string $dir Directory path * @return int Number of files and folders removed */ function cot_rmdir($dir) { static $cnt = 0; $dp = opendir($dir); while ($f = readdir($dp)) { $path = $dir . '/' . $f; if ($f != '.' && $f != '..' && is_dir($path)) { cot_rmdir($path); } elseif ($f != '.' && $f != '..') { unlink($path); $cnt++; } } closedir($dp); rmdir($dir); $cnt++; return $cnt; }
<?php /** * Removes HTML Purifier Serializer cache folder * * @package HTML Purifier * @copyright (c) Cotonti Team * @license https://github.com/Cotonti/Cotonti/blob/master/License.txt */ defined('COT_CODE') or die('Wrong URL'); if (file_exists($cfg['cache_dir'] . '/htmlpurifier')) { cot_rmdir($cfg['cache_dir'] . '/htmlpurifier'); }