X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FFileSystem.php;fp=src%2FUtil%2FFileSystem.php;h=33e04788e6921b184ad600f904300b2f2aea50e3;hb=6b2c28e2d72d618bd46b9264f9e348725d7b5f5f;hp=0000000000000000000000000000000000000000;hpb=0e84a843a4e9c77df3a6191b1a6906059fb22fe5;p=friendica.git diff --git a/src/Util/FileSystem.php b/src/Util/FileSystem.php new file mode 100644 index 0000000000..33e04788e6 --- /dev/null +++ b/src/Util/FileSystem.php @@ -0,0 +1,64 @@ +errorMessage, $dirname)); + } + + return $dirname; + } elseif (isset($dirname) && is_dir($dirname)) { + return $dirname; + } else { + return ''; + } + } + + public function createStream(string $url) + { + $directory = $this->createDir($url); + set_error_handler([$this, 'customErrorHandler']); + if (!empty($directory)) { + $url = $directory . DIRECTORY_SEPARATOR . pathinfo($url, PATHINFO_BASENAME); + } + + $stream = fopen($url, 'ab'); + restore_error_handler(); + + if (!is_resource($stream)) { + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $url)); + } + + return $stream; + } + + private function customErrorHandler($code, $msg) + { + $this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg); + } +}