file_exists($path)) { $path = Filesystem::normalizePath($dir . '/' . $name . ' (' . $i . ')' . $ext); $i++; } return $path; } /** * get default share folder * * @param View|null $view * @param string|null $userId * @return string */ public static function getShareFolder(?View $view = null, ?string $userId = null): string { if ($view === null) { $view = Filesystem::getView(); } $config = \OC::$server->getConfig(); $systemDefault = $config->getSystemValue('share_folder', '/'); $allowCustomShareFolder = $config->getSystemValueBool('sharing.allow_custom_share_folder', true); // Init custom shareFolder $shareFolder = $systemDefault; if ($userId !== null && $allowCustomShareFolder) { $shareFolder = $config->getUserValue($userId, Application::APP_ID, 'share_folder', $systemDefault); } // Verify and sanitize path $shareFolder = Filesystem::normalizePath($shareFolder); // Init path if folder doesn't exists if (!$view->file_exists($shareFolder)) { $dir = ''; $subdirs = explode('/', $shareFolder); foreach ($subdirs as $subdir) { $dir = $dir . '/' . $subdir; if (!$view->is_dir($dir)) { $view->mkdir($dir); } } } return $shareFolder; } /** * set default share folder * * @param string $shareFolder */ public static function setShareFolder($shareFolder) { \OC::$server->getConfig()->setSystemValue('share_folder', $shareFolder); } }