3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core\Storage\Type;
24 use Friendica\Core\Config\Capability\IManageConfigValues;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Storage\Capability\ICanConfigureStorage;
29 * Filesystem based storage backend configuration
31 class FilesystemConfig implements ICanConfigureStorage
33 // Default base folder
34 const DEFAULT_BASE_FOLDER = 'storage';
36 /** @var IManageConfigValues */
46 * Returns the current storage path
50 public function getStoragePath(): string
52 return $this->storagePath;
56 * Filesystem constructor.
58 * @param IManageConfigValues $config
61 public function __construct(IManageConfigValues $config, L10n $l10n)
63 $this->config = $config;
66 $path = $this->config->get('storage', 'filesystem_path', self::DEFAULT_BASE_FOLDER);
67 $this->storagePath = rtrim($path, '/');
73 public function getOptions(): array
78 $this->l10n->t('Storage base path'),
80 $this->l10n->t('Folder where uploaded files are saved. For maximum security, This should be a path outside web server folder tree')
88 public function saveOptions(array $data): array
90 $storagePath = $data['storagepath'] ?? '';
91 if ($storagePath === '' || !is_dir($storagePath)) {
93 'storagepath' => $this->l10n->t('Enter a valid existing folder')
96 $this->config->set('storage', 'filesystem_path', $storagePath);
97 $this->storagePath = $storagePath;