Hi,
The File Manager can be used to upload files in the Modx directory. It works well, however it doesn’t allow the restriction on what folder a user can access or not.
A legal adviser should be able to upload a new contract but not be able to look what is inside the Finance folder e.g.
As a solution, I’m using a file server to define the folder a user can upload to and download from.
At the end I have on my server a directory structure like
/modx
and
/fileserver/Documents/
- Legal
- Projects
- Finance
Now using Modx for the end-user front access, I have created documents Legal, Projects and Finance.
What kind of code should I use in those documents in order to get the list of documents in their associated folder, so that the user can then click on it to download it?
Is there a way to make it dynamic, so that the folder it browses on the fileserver is the same as the modx document title?
I think it’s probably something around @BIND though I didn’t quite get a grasp on using it.
If you have a better solution to recommend to implement those requirements, I’m open to alternatives.
And if this was explained somewhere already and I missed it, apologies and let me know the link for it.
Thanks for your help.
Check into the FIleDownload snippet/plug-in to handle the downloads.
As for the upload issue, you can set a custom path for each manager user’s file manager and resource browser by editing these settings in the individual user settings.
This is mostly off the top of my head, but this snippet code should read the directory whose path you pass in the snippet call. All you have to do is set $dir in the snippet call to the path of the directory you want to read. You may have to modify the $link line and will probably want to add some styling code. There should also be some "elses" to handle errors (and make it easier to debug).
$output = "";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
// iterate over file list to create full directory array
while (($filename = readdir($dh)) !== false) {
if (($filename != ".") && ($filename != "..") ) { // skip self, parent
$dir_array[] = $filename; // add the filename to the array
}
}
closedir($dh); // close directory
}
foreach($dir_array as $temp_value) {
$link = $modx->config['base_url'].$temp_value; // create URL
output .= '<a href ="';
output .= $link;
output .= '">';
output .= $temp_value;
output .= '</a>';
output .='<br />';
}
return $output;
hope this helps
Bob
Thanks, I will check the FileDownload snippet.
For the file manager upload path, that won’t work in our case as we need to provide access to various folders in various directories. Unfortunately, they cannot be grouped per access right under a single directory.
Bob, for the $dir variable, how could I set it properly?
I will have in modx tree:
ClientOne/
Legal Documents
Project Documents
Finance Documents
ClientTwo/
Legal Documents
Project Documents
Finance Documents
In the file server, it will be:
/path_to_folder/ClientOne/
Legal Documents
Projects Documents
Finance Documents
/path_to_folder/ClientTwo/
Legal Documents
Projects Documents
Finance Documents
So when a client clicks on the Legal Documents, I would need the $dir to become /path_to_folder/<parent directory name>/<current document name> so I get the Legal Documents for that particular client.
See what I mean?
Maybe using a tv to define the document folder.
Thanks.
Julian
Julian,
If I’m understanding you correctly, you could use (in the snippet) $currentUserName=$modx->getLoginUserName() and just add $currentUserName to the path for each link.
Bob
hi Bob,
I’d like to be able to define the dir variable as being path/clientname/foldername, where:
- path can be hardcoded as /filemanager e.g.
- clientname would be the upper directory of the document name, as there could be many login usernames pointing to the same client
- foldername is the name of the document
so how could I construct the dir variable?
Julian