Different storages for multiple users
Note: Each website usually has only one storage and all the users browse the same directory. Using different per-user storages usually (but not always) means they actually edit different websites and separate Premium licenses should be used in such cases (see Licensing). If you build SaaS where different users need to have individual storage, please contact us first to check can you use multiple storage for free or separate licenses are required. Without an additional agreement the license grants only one storage per website.
Sometimes when you have multiple users on your website (on your app) there are two ways to manage your storage:
- All users have one folder they manage (usually on small websites).
- Each user has an individual directory it uploads to (used for isolating users on SaaS apps or on big websites).
This article describes the second approach.
Configure user directories
In order to give to each user a separate directory, you need some code that will change the configuration of Flmngr based on the user ID.
For example, each user has a login used in your system as a directory name, for example, your structure can look like:
files/
user1/
user2/
...
There are two places where you need to specify the user's folder: on the backend (directory dirFiles
- where files are placed) and on the frontend (parameter urlFiles
- how to generate URLs of selected files).
Server-side code sample
Find the right place in a controller handling file manager and change configuration passed into flmngrRequest()
call:
// Get string unique ID of the current user by a way your CMS/framework provides.
$userId = ...
// Substitute it into the configuration
FlmngrServer::flmngrRequest(
array(
// Directory of your files storage
'dirFiles' => '/var/www/files/' . $userId,
// Optionally: if you wish to use separate directory for cache files
// This is handy when your "dirFiles" is slower a local disk,
// for example this is a drive mounted over a network.
//'dirCache' => '/var/www/cache' . $userId,
)
);
Map directories to URLs
After setting user directories you need to explain to the file manager how to generate URLs for selected files.
Pass the config depending on your integration:
NPM
React
Snippet
TinyMCE
CKEditor 4
CKEditor 5
Froala
import Flmngr from "flmngr";
// Get string unique ID of the current user by a way your CMS/framework provides.
// Usually this can be found in Cookies.
// This value must be equal to "userId" you pass on the backend.
let userId = getUserId(); // your function
Flmngr.open({
apiKey: "FLMN24RR1234123412341234", // your API key here
urlFileManager: 'https://example.com/scripts/flmngr.php', // your Flmngr backend
urlFiles: 'https://example.com/files/user' + userId, // build URL of the user
isMultiple: false, // let selecting a single file
onFinish: (files) => {
console.log("User picked:");
console.log(files);
}
});