Skip to content

User storage folder

pavel edited this page Mar 17, 2018 · 1 revision

Local storage folder

There are 2 configuration options which affects the location of a storage folder of user files:

serverRoot (bool)
fileRoot (bool|string)

By combining values of these options you can change target location of storage folder.

serverRoot - "true" by default, means that storage folder location is defined relative to the server document root folder. Set value to "false" in case the storage folder of user files is located outside server root folder. If fileRoot options is set to "false", serverRoot value is ignored - always "true".

fileRoot - "false" by default, means that storage folder is located under server document root folder and named "userfiles". You can set specific path to the storage folder of user files instead of "false" value with the following rules:

  • absolute path in case serverRoot set to "false", e.g. "/var/www/html/filemanager/userfiles/"
  • relative path in case serverRoot set to "true", e.g. "/filemanager/userfiles/"

You could change the options values as it's described in the Configuration section in two ways:

1. Upon configuring storage instance

$config = [
    "options" => [
        "serverRoot" => true,
        "fileRoot" => false,
    ],
];

$local = new \RFM\Repository\Local\Storage($config);

2. Using "setRoot" storage method

$local = new \RFM\Repository\Local\Storage();

$local->setRoot('user_folder', true, true);

Parameters of the setRoot method are as follows:

  1. Relative or absolute path to folder (see examples below)
  2. whether to create folder if it does not exist
  3. same as "serverRoot" configuration option

Local storage folder setup examples

  1. Default case - user folder located inside the RichFilemanager root folder

The default user folder is named "userfiles" and located inside the RichFilemanager root folder. After the application is deployed it should automatically detect the "userfiles" folder location, so you don't need to make any changes in configuration options, which looks as follows by default:

    "serverRoot" => true,
    "fileRoot" => false,
  1. Specify user folder located UNDER server document root folder
  • Setup configuration options
    "serverRoot" => true,
    "fileRoot" => "/filemanager/files/", // relative path to a storage folder of user files
  • Utilize setRoot method (alternative way)
    $local->setRoot("/filemanager/files/", true, true);
  1. Specify user folder located OUTSIDE server document root folder
  • Setup configuration options
    "serverRoot" => false,
    "fileRoot" => "/var/www/html/filemanager/files/", // absolute server path
  • Utilize setRoot method (alternative way)
    $local->setRoot("/var/www/html/filemanager/files/", true, false);

IMPORTANT: If a storage folder of user files is located outside server document root folder, then the application is unable to define absolute URL to user files. RichFilemanager still able to preview the files, but by reading them via connector URL instead of using absolute URL.

That means the preview URL will look similar to:

http://mydomain.com/my_project/filemanager/connectors/php/filemanager.php?mode=readfile&path=/image.jpg

Instead of absolute direct URL:

http://mydomain.com/my_project/filemanager/files/image.jpg

This may cause problems in case integration RichFilemanager with WYSIWYG editors.

Luckily in most cases it's possible to specify URL to access storage folder explicitly. See Handle preview URL RichFilemanager wiki article for the details.

Setting dynamic user folder based on session

This example shows how to set storage folder path dynamically based on session variable.

session_start();

// supposed that user folder name is stored in "userfolder" session variable
$folderPath = "/filemanager/files/" . $_SESSION["userfolder"];

$app = new \RFM\Application();

$local = new \RFM\Repository\Local\Storage();

// example to setup files root folder
$local->setRoot($folderPath, true, true);

$app->setStorage($local);

// set application API
$app->api = new RFM\Api\LocalApi();

$app->run();

AWS S3 storage folder

Since AWS S3 storage root folder depends on your S3 bucket configuration you are only able to change user folder under the bucket. Use "setRoot" storage method:

$s3 = new \RFM\Repository\S3\Storage();

$s3->setRoot('user_folder', true);

Parameters of the setRoot method are as follows:

  1. Relative path to S3 storage "folder" under the bucket.
  2. Whether to create folder if it does not exist