Search code examples
javascriptresponsive-filemanager

Restricting Responsive FileManager Folder With JS?


I am using Responsive FileManager extensively as a standalone (not part of a general text editor). I sometimes call it multiple times on one page. However, each time I want it to be restricted to a certain folder—not merely so it defaults to a folder, but so the user can't navigate to any other folders at all.

The only way I have found to restrict a folder in Responsive FileManager is by setting the PHP sesssion variable:

$_SESSION['RF']['subfolder']

However, this is a problem for different folders that need to be there on the same page, and in general it's impractical because the restriction should be specific to the file manager call, not user-specific like a session. Also, I don't need it to be absolutely impossible to navigate to other folders in a secure way, it's OK if someone who knows how to use the browser debugger navigates somewhere else. I merely want to prevent casual users from doing this.

Is there any way to do this with a JS config option, or some other per-call and not per-user way?

Their feature list says:

You can set a subfolder as the root and change the configuration for each user, page or FileManager call.

But I was not able to find a per-call folder restriction in their docs.


Solution

  • Here is a simple tweak to achieve this . Responisve filemanager calls the dialog.php with some parameters appended like type .What I did is : introduce a new param and put a check for that on the server side to set the uploads path dynamically .

    Consider your uploads directory is uploads and you have user1 , user2 , user3 as sub directories , So , in that case we will be setting the uploads path and current path in the config.php dynamically from the parameters which we will be passing while calling the dialog.php

    In the filemanager/config/config.php Append these lines

    if( isset( $_GET['MY_UPLOAD_PATH']))
     {
       $config['upload_dir']   =  $config['upload_dir'] . $_GET['MY_UPLOAD_PATH']."/" ;
       $config['current_path'] =  $config['current_path'] . $_GET['MY_UPLOAD_PATH']."/" ;
    }
    

    In the filemanager/dialog.php Find this line $get_params = http_build_query($get_params); And just before that line add

      if(isset($_GET['MY_UPLOAD_PATH'])){
         $get_params['MY_UPLOAD_PATH'] = $_GET['MY_UPLOAD_PATH'] ;
       }
    

    Now change your variable

    $data['file_explorer'] = base_url('assets/resources/filemanager/dialog.php?type=0');

    to

     $data['file_explorer'] = base_url('assets/resources/filemanager/dialog.php?type=0&MY_UPLOAD_PATH=user1');
    

    Just change the value of the MY_UPLOAD_PATH param and the dialog.php will show only that particular directory .