Util/FileHandler
* try to create directory if file is to be written into nonexistent directory
This commit is contained in:
parent
10de320616
commit
e614f415a9
1 changed files with 6 additions and 1 deletions
|
|
@ -1293,6 +1293,11 @@ abstract class Util
|
|||
public static function writeFile($file, $content)
|
||||
{
|
||||
$success = false;
|
||||
|
||||
$parentDir = mb_substr($file, 0, mb_strrpos($file, '/'));
|
||||
if (!self::writeDir($parentDir))
|
||||
return false;
|
||||
|
||||
if ($handle = @fOpen($file, "w"))
|
||||
{
|
||||
if (fWrite($handle, $content))
|
||||
|
|
@ -1314,7 +1319,7 @@ abstract class Util
|
|||
public static function writeDir(string $dir, bool &$exist = true) : bool
|
||||
{
|
||||
// remove multiple slashes; trailing slashes
|
||||
$dir = preg_replace(['/\/+/', '/\/$/'], ['/', ''], $dir);
|
||||
$dir = preg_replace(['/\/+/', '/\/$/'], ['/', ''], $dir) ?: '.';
|
||||
$exist = is_dir($dir);
|
||||
|
||||
if ($exist)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue