From 683a39dded3ae5543ea48517e301537cef506db5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 31 Aug 2020 11:01:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- function.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/function.php b/function.php index 01da6ab4..65cc6045 100644 --- a/function.php +++ b/function.php @@ -44,11 +44,16 @@ if (!function_exists('storage')) { { $basePath = Snowflake::getStoragePath(); if (empty($path)) { - return $basePath . '/' . $fileName; + $fileName = $basePath . '/' . $fileName; } else if (empty($fileName)) { - return initDir($basePath, $path); + $fileName = initDir($basePath, $path); + } else { + $fileName = initDir($basePath, $path) . '/' . $fileName; } - return initDir($basePath, $path) . $fileName; + if (!file_exists($fileName)) { + touch($fileName); + } + return $fileName; } @@ -61,16 +66,17 @@ if (!function_exists('storage')) { function initDir($basePath, $path) { $explode = array_filter(explode('/', $path)); + $_path = '/' . trim($basePath, '/') . '/'; foreach ($explode as $value) { - $path .= $value . '/'; - if (!is_dir($basePath . $path)) { - mkdir($basePath . $path); + $_path .= $value . '/'; + if (!is_dir(rtrim($_path, '/'))) { + mkdir(rtrim($_path, '/')); } - if (!is_dir($basePath . $path)) { - throw new Exception('System error, directory ' . $basePath . $path . ' is not writable'); + if (!is_dir($_path)) { + throw new Exception('System error, directory ' . $_path . ' is not writable'); } } - return realpath($basePath . $path); + return realpath($_path); }