elFinderConnector::run PHP Метод

run() публичный Метод

Execute elFinder command and output result
Автор: Dmitry (dio) Levashov
public run ( ) : void
Результат void
    public function run()
    {
        $isPost = $this->reqMethod === 'POST';
        $src = $isPost ? $_POST : $_GET;
        $maxInputVars = !$src || isset($src['targets']) ? ini_get('max_input_vars') : null;
        if ((!$src || $maxInputVars) && ($rawPostData = file_get_contents('php://input'))) {
            // for max_input_vars and supports IE XDomainRequest()
            $parts = explode('&', $rawPostData);
            if (!$src || $maxInputVars < count($parts)) {
                $src = array();
                foreach ($parts as $part) {
                    list($key, $value) = array_pad(explode('=', $part), 2, '');
                    $key = rawurldecode($key);
                    if (preg_match('/^(.+?)\\[([^\\[\\]]*)\\]$/', $key, $m)) {
                        $key = $m[1];
                        $idx = $m[2];
                        if (!isset($src[$key])) {
                            $src[$key] = array();
                        }
                        if ($idx) {
                            $src[$key][$idx] = rawurldecode($value);
                        } else {
                            $src[$key][] = rawurldecode($value);
                        }
                    } else {
                        $src[$key] = rawurldecode($value);
                    }
                }
                $_POST = $this->input_filter($src);
                $_REQUEST = $this->input_filter(array_merge_recursive($src, $_REQUEST));
            }
        }
        if (isset($src['targets']) && $this->elFinder->maxTargets && count($src['targets']) > $this->elFinder->maxTargets) {
            $error = $this->elFinder->error(elFinder::ERROR_MAX_TARGTES);
            $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_MAX_TARGTES)));
        }
        $cmd = isset($src['cmd']) ? $src['cmd'] : '';
        $args = array();
        if (!function_exists('json_encode')) {
            $error = $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_JSON);
            $this->output(array('error' => '{"error":["' . implode('","', $error) . '"]}', 'raw' => true));
        }
        if (!$this->elFinder->loaded()) {
            $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_CONF, elFinder::ERROR_CONF_NO_VOL), 'debug' => $this->elFinder->mountErrors));
        }
        // telepat_mode: on
        if (!$cmd && $isPost) {
            $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UPLOAD, elFinder::ERROR_UPLOAD_TOTAL_SIZE), 'header' => 'Content-Type: text/html'));
        }
        // telepat_mode: off
        if (!$this->elFinder->commandExists($cmd)) {
            $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_UNKNOWN_CMD)));
        }
        // collect required arguments to exec command
        $hasFiles = false;
        foreach ($this->elFinder->commandArgsList($cmd) as $name => $req) {
            if ($name === 'FILES') {
                if (isset($_FILES)) {
                    $hasFiles = true;
                } elseif ($req) {
                    $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
                }
            } else {
                $arg = isset($src[$name]) ? $src[$name] : '';
                if (!is_array($arg) && $req !== '') {
                    $arg = trim($arg);
                }
                if ($req && $arg === '') {
                    $this->output(array('error' => $this->elFinder->error(elFinder::ERROR_INV_PARAMS, $cmd)));
                }
                $args[$name] = $arg;
            }
        }
        $args['debug'] = isset($src['debug']) ? !!$src['debug'] : false;
        $args = $this->input_filter($args);
        if ($hasFiles) {
            $args['FILES'] = $_FILES;
        }
        $this->output($this->elFinder->exec($cmd, $args));
    }

Usage Example

Пример #1
0
 public function handleOptions()
 {
     $opts = array('debug' => true, 'roots' => array(array('driver' => 'LocalFileSystem', 'path' => APP_DIR . '/media/' . $_GET["path"], 'URL' => '/www/media/' . $_GET["path"], 'uploadDeny' => array('all'), 'uploadAllow' => array('image', 'text/plain'), 'uploadOrder' => array('deny', 'allow'), 'accessControl' => 'access', 'fileMode' => 0644, 'attributes' => $this->getHiddenDirectories()), array('driver' => 'LocalFileSystem', 'path' => APP_DIR . '/images', 'URL' => '/www/images', 'uploadDeny' => array('all'), 'uploadAllow' => array('image', 'text/plain'), 'uploadOrder' => array('deny', 'allow'), 'accessControl' => 'access', 'fileMode' => 0644, 'attributes' => $this->getHiddenDirectories())));
     // Run elFinder
     $connector = new \elFinderConnector(new \elFinder($opts));
     $connector->run();
 }
All Usage Examples Of elFinderConnector::run