3 namespace Friendica\Util;
10 * @brief Returns the base filesystem path of the App
12 * It first checks for the internal variable, then for DOCUMENT_ROOT and
15 * @param string|null $basepath
19 * @throws \Exception if directory isn't usable
21 public static function create($basepath)
23 if (!$basepath && !empty($_SERVER['DOCUMENT_ROOT'])) {
24 $basepath = $_SERVER['DOCUMENT_ROOT'];
27 if (!$basepath && !empty($_SERVER['PWD'])) {
28 $basepath = $_SERVER['PWD'];
31 return self::getRealPath($basepath);
35 * @brief Returns a normalized file path
37 * This is a wrapper for the "realpath" function.
38 * That function cannot detect the real path when some folders aren't readable.
39 * Since this could happen with some hosters we need to handle this.
41 * @param string $path The path that is about to be normalized
42 * @return string normalized path - when possible
44 public static function getRealPath($path)
46 $normalized = realpath($path);
48 if (!is_bool($normalized)) {
57 * @brief Checks if a given directory is usable for the system
60 * @param bool $check_writable
62 * @return boolean the directory is usable
64 public static function isDirectoryUsable($directory, $check_writable = true)
66 if ($directory == '') {
67 Core\Logger::log('Directory is empty. This shouldn\'t happen.', Core\Logger::DEBUG);
71 if (!file_exists($directory)) {
72 Core\Logger::log('Path "' . $directory . '" does not exist for user ' . Core\System::getUser(), Core\Logger::DEBUG);
76 if (is_file($directory)) {
77 Core\Logger::log('Path "' . $directory . '" is a file for user ' . Core\System::getUser(), Core\Logger::DEBUG);
81 if (!is_dir($directory)) {
82 Core\Logger::log('Path "' . $directory . '" is not a directory for user ' . Core\System::getUser(), Core\Logger::DEBUG);
86 if ($check_writable && !is_writable($directory)) {
87 Core\Logger::log('Path "' . $directory . '" is not writable for user ' . Core\System::getUser(), Core\Logger::DEBUG);