mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Util/FileHandler
* try to create directory if file is to be written into nonexistent directory
This commit is contained in:
@@ -1293,6 +1293,11 @@ abstract class Util
|
|||||||
public static function writeFile($file, $content)
|
public static function writeFile($file, $content)
|
||||||
{
|
{
|
||||||
$success = false;
|
$success = false;
|
||||||
|
|
||||||
|
$parentDir = mb_substr($file, 0, mb_strrpos($file, '/'));
|
||||||
|
if (!self::writeDir($parentDir))
|
||||||
|
return false;
|
||||||
|
|
||||||
if ($handle = @fOpen($file, "w"))
|
if ($handle = @fOpen($file, "w"))
|
||||||
{
|
{
|
||||||
if (fWrite($handle, $content))
|
if (fWrite($handle, $content))
|
||||||
@@ -1314,7 +1319,7 @@ abstract class Util
|
|||||||
public static function writeDir(string $dir, bool &$exist = true) : bool
|
public static function writeDir(string $dir, bool &$exist = true) : bool
|
||||||
{
|
{
|
||||||
// remove multiple slashes; trailing slashes
|
// remove multiple slashes; trailing slashes
|
||||||
$dir = preg_replace(['/\/+/', '/\/$/'], ['/', ''], $dir);
|
$dir = preg_replace(['/\/+/', '/\/$/'], ['/', ''], $dir) ?: '.';
|
||||||
$exist = is_dir($dir);
|
$exist = is_dir($dir);
|
||||||
|
|
||||||
if ($exist)
|
if ($exist)
|
||||||
|
|||||||
Reference in New Issue
Block a user