1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
error_reporting(0); // Set E_ALL for debuging |
4
|
|
|
|
5
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderConnector.class.php'; |
6
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinder.class.php'; |
7
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeDriver.class.php'; |
8
|
|
|
include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeLocalFileSystem.class.php'; |
9
|
|
|
// Required for MySQL storage connector |
10
|
|
|
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeMySQL.class.php'; |
11
|
|
|
// Required for FTP connector support |
12
|
|
|
// include_once dirname(__FILE__).DIRECTORY_SEPARATOR.'elFinderVolumeFTP.class.php'; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Simple function to demonstrate how to control file access using "accessControl" callback. |
17
|
|
|
* This method will disable accessing files/folders starting from '.' (dot) |
18
|
|
|
* |
19
|
|
|
* @param string $attr attribute name (read|write|locked|hidden) |
20
|
|
|
* @param string $path file path relative to volume root directory started with directory separator |
21
|
|
|
* @return bool|null |
22
|
|
|
**/ |
23
|
|
|
function access($attr, $path, $data, $volume) { |
|
|
|
|
24
|
|
|
return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot) |
25
|
|
|
? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true |
26
|
|
|
: null; // else elFinder decide it itself |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
// Documentation for connector options: |
31
|
|
|
// https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options |
32
|
|
|
$opts = array( |
33
|
|
|
// 'debug' => true, |
34
|
|
|
'roots' => array( |
35
|
|
|
array( |
36
|
|
|
'driver' => 'LocalFileSystem', // driver for accessing file system (REQUIRED) |
37
|
|
|
'path' => '../files/', // path to files (REQUIRED) |
38
|
|
|
'URL' => dirname($_SERVER['PHP_SELF']) . '/../files/', // URL to files (REQUIRED) |
39
|
|
|
'accessControl' => 'access' // disable and hide dot starting files (OPTIONAL) |
40
|
|
|
) |
41
|
|
|
) |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
// run elFinder |
45
|
|
|
$connector = new elFinderConnector(new elFinder($opts)); |
46
|
|
|
$connector->run(); |
47
|
|
|
|
48
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.