basePath . '/utils/WechatMerchant/cert'; $this->delFileUnderDir($dir); } /** * @description: * @param {*} * @return {*} */ public function clearImages() { $dir = \Yii::$app->basePath . '/runtime/image'; $this->delFileUnderDir($dir); $dir = \Yii::$app->basePath . '/web/temp'; $this->delFileUnderDir($dir); } /** * @description: * @param {*} * @return {*} */ public function clearData() { return cache()->flush(); } /** * @description: * @param {*} * @return {*} */ public function clearUpdata() { $dir = \Yii::$app->basePath . '/temp/update'; $this->delFileUnderDir($dir); } //循环目录下的所有文件 private function delFileUnderDir($dirName, $delDir = false, $ignoreList = []) { // 判断是否存在该目录 if (file_exists("$dirName")) { if ($handle = opendir("$dirName")) { while (false !== ($item = readdir($handle))) { if ($item != "." && $item != ".." && !in_array($item, $ignoreList)) { if (is_dir("$dirName/$item")) { $this->delFileUnderDir("$dirName/$item", true, $ignoreList); } else { unlink("$dirName/$item"); } } } closedir($handle); if ($delDir) { rmdir("$dirName"); } } } } }