<?phpnamespace ZX\Tool;use Exception;use ZX\Generator;class File{//写入文件 $append强制追加内容public static function writeToFile(string $fileName, string $filePath, string $content, string $model = 'a', bool $append = false){try {$path = $filePath . DIRECTORY_SEPARATOR . $fileName;if ($append) {$file = fopen($path, $model);fwrite($file, $content);fclose($file);} else {if (file_exists($path)) {return true;} else {$file = fopen($path, $model);fwrite($file, $content);fclose($file);}}} catch (Exception $e) {throw new Exception($e->getMessage());}}public static function deldir($path){//如果是目录则继续if (is_dir($path)) {//扫描一个文件夹内的所有文件夹和文件并返回数组$p = scandir($path);foreach ($p as $val) {//排除目录中的.和..if ($val != "." && $val != "..") {//如果是目录则递归子目录,继续操作if (is_dir($path . $val)) {//子目录中操作删除文件夹和文件self::deldir($path . $val . '/');//目录清空后删除空文件夹rmdir($path . $val . '/');} else {//如果是文件直接删除unlink($path . $val);}}}}}public static function makeFile(string $path){if (!is_dir($path)) {mkdir($path, 0755, true);}}/*** @param bool $custom 模板是否自定义 true使用自定义模板,false 使用提供的模板* @param string $filePath 模板文件名称* @param string $templateName 模板名称* @return false|string* @throws Exception*/public static function getFileContent(Generator $Generator, string $filePath = '', string $templateName = ''){if (empty($templateName)) {throw new Exception('template name is null');}$templatePath = $Generator::getTemplatePath() . DIRECTORY_SEPARATOR . $templateName . DIRECTORY_SEPARATOR . $filePath;if (!file_exists($templatePath)) {throw new Exception('file is not exist');}$content = file_get_contents($templatePath);return $content;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。