Elfinder: How to use custom replacer with the Sanitizer plugin

Created on 4 May 2018  路  6Comments  路  Source: Studio-42/elFinder

i have a filename "test 20.1.txt" and i sanitize ( . ) and replace it "new". and the output is test 20 new.1new.text. my question is if it possible to sanitize the dot that next to extension name? if possible can you help me how TIA

howto

Most helpful comment

thank you so much @nao-pon and @CodeLyokoXtEAM

All 6 comments

@hayes-seyah09354085977 You can use an option callback.

'plugin' => array(
    'Sanitizer' => array(
        'enable' => true,
        'callBack' => function($name, $options) {
            $ext = '';
            $pos = strrpos($name, '.');
            if ($pos !== false) {
                $ext = substr($name, $pos);
                $name = substr($name, 0, $pos);
            }
            return str_replace('.', 'new', $name) . $ext;
        }
    )
)

is this right?

$opts = array(
    // 'debug' => true,
    'bind' => array(
        'upload.pre mkdir.pre mkfile.pre rename.pre archive.pre ls.pre' => array(
            'Plugin.Sanitizer.cmdPreprocess'
        ),
        'ls' => array(
            'Plugin.Sanitizer.cmdPostprocess'
        ),
        'upload.presave' => array(
            'Plugin.Sanitizer.onUpLoadPreSave'
        )
    ),
    // global configure (optional)
    'plugin' => array(
        'Sanitizer' => array(
            'enable' => true,
            'callBack' => function($name, $options) {
                $ext = '';
                $pos = strrpos($name, '.');
                if ($pos !== false) {
                    $ext = substr($name, $pos);
                    $name = substr($name, 0, $pos);
                }
                return str_replace('.', 'new', $name) . $ext;
            }
        )
        ),
    'roots' => array(
        // Items volume
        array(
            'driver'        => 'LocalFileSystem',           // driver for accessing file system (REQUIRED)
            'path'          => '../files/',                 // path to files (REQUIRED)
            'URL'           => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED)
            'trashHash'     => 't1_Lw',                     // elFinder's hash of trash folder
            'winHashFix'    => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
            'uploadDeny'    => array('all'),                // All Mimetypes not allowed to upload
            'uploadAllow'   => array('image', 'text/plain'),// Mimetype `image` and `text/plain` allowed to upload
            'uploadOrder'   => array('deny', 'allow'),      // allowed Mimetype `image` and `text/plain` only
            'accessControl' => 'access'                     // disable and hide dot starting files (OPTIONAL)
        ),
        // Trash volume
        array(
            'id'            => '1',
            'driver'        => 'Trash',
            'path'          => '../files/.trash/',
            'tmbURL'        => dirname($_SERVER['PHP_SELF']) . '/../files/.trash/.tmb/',
            'winHashFix'    => DIRECTORY_SEPARATOR !== '/', // to make hash same to Linux one on windows too
            'uploadDeny'    => array('all'),                // Recomend the same settings as the original volume that uses the trash
            'uploadAllow'   => array('image', 'text/plain'),// Same as above
            'uploadOrder'   => array('deny', 'allow'),      // Same as above
            'accessControl' => 'access',                    // Same as above
        )
    )
);

i test and nothing happen

@hayes-seyah09354085977 Yes, It correct. I tested with elFinder 2.1.38. Rename "A.txt" to "A.B.C.txt", it became "AnewBnewC.txt".

the output must be A.B.C new.txt how to do that?

@hayes-seyah09354085977
if you want to change "A.B.C.txt" to "A.B.C new.txt"
change code return str_replace('.', 'new', $name) . $ext; to return $name . ' new' . $ext;

thank you so much @nao-pon and @CodeLyokoXtEAM

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  11Comments

richard100589 picture richard100589  路  13Comments

hayes-seyah09354085977 picture hayes-seyah09354085977  路  17Comments

isreehari picture isreehari  路  12Comments

Offerel picture Offerel  路  10Comments