PHP code example of fpokoj / richfilemanager-php

1. Go to this page and download the library: Download fpokoj/richfilemanager-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fpokoj / richfilemanager-php example snippets


$app = new \RFM\Application();

// local filesystem storage
$local = new \RFM\Repository\Local\Storage();
$app->setStorage($local);

// AWS S3 storage instance
$s3 = new \RFM\Repository\S3\Storage();
$app->setStorage($s3);

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

// AWS S3 API
$app->api = new RFM\Api\AwsS3Api();

$app->run();

$config = [
    'security' => [
        'readOnly' => true,
        'extensions' => [
            'policy' => 'ALLOW_LIST',
            'restrictions' => [
                'jpg',
                'jpe',
                'jpeg',
                'gif',
                'png',
                'html',
            ],
        ],
    ],
];

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

$config_s3 = [
    'images' => [
        'thumbnail' => [
            'dir' => 's3_thumbs',
            'useLocalStorage' => true,
        ],
    ],
    'credentials' => [
        'region' => 'your region',
        'bucket' => 'your aws s3 bucket',
        'credentials' => [
            'key' => 'your aws s3 key',
            'secret' => 'your aws s3 secret',
        ],
        'defaultAcl' => \RFM\Repository\S3\StorageHelper::ACL_PUBLIC_READ,
        'debug' => false,
    ],
];

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

session_start();

function fm_authenticate()
{
    return $_SESSION['user_type'] === "admin";
}

function fm_has_read_permission($filepath)
{
    if ($filepath === "/var/www/userfiles/some_file.txt") {
        return false;    
    }
    
    return true;
}

function fm_has_write_permission($filepath)
{
    if ($filepath === "/var/www/userfiles/some_file.txt") {
        return false;    
    }
    
    return true;
}

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

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

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

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

    "serverRoot" => true,
    "fileRoot" => false,

    "serverRoot" => true,
    "fileRoot" => "/filemanager/files/", // relative path to a storage folder of user files

    $local->setRoot("/filemanager/files/", true, true);

    "serverRoot" => false,
    "fileRoot" => "/var/www/html/filemanager/files/", // absolute server path

    $local->setRoot("/var/www/html/filemanager/files/", true, false);

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();

// set relative path to storage root folder
$local->setRoot($folderPath, true);

$app->setStorage($local);

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

$app->run();

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

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

$config = [
    'logger' => [
        'enabled' => true,
        'file' => '/var/log/filemanager.log',
    ],
];

$local = new \RFM\Repository\Local\Storage($config);
json
{
  "vocoder/richfilemanager-php": "*",
    "aws/aws-sdk-php": "^3.18.0"
  }
}