Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.1.27 LocalFileSystem upload error #2143

Closed
bitbybit opened this issue Aug 12, 2017 · 13 comments
Closed

2.1.27 LocalFileSystem upload error #2143

bitbybit opened this issue Aug 12, 2017 · 13 comments

Comments

@bitbybit
Copy link

Hi

With new 2.1.27 version i get following result of uploading files (LocalFileSystem driver):

error:
["errCmdParams", "upload"]

Is it expected behaviour? Did some APIs change?

@nao-pon
Copy link
Member

nao-pon commented Aug 15, 2017

@bitbybit There is no API change of the Upload command. The Upload command requires target and FILES parameters. Are they sended in that request?

@bitbybit
Copy link
Author

Chrome console output:

POST [...] HTTP/1.1
Host: [...]
Connection: keep-alive
Content-Length: 380500
Origin: [...]
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.78 Chrome/60.0.3112.78 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryUPRimTCAEA2P1c38
Accept: */*
DNT: 1
Referer: [...]
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,en-US;q=0.8,ru;q=0.6,en;q=0.4
Cookie: [...]

------WebKitFormBoundaryUPRimTCAEA2P1c38
Content-Disposition: form-data; name="cmd"

upload
------WebKitFormBoundaryUPRimTCAEA2P1c38
Content-Disposition: form-data; name="current"

l1_Lw
------WebKitFormBoundaryUPRimTCAEA2P1c38
Content-Disposition: form-data; name="upload[]"; filename="dims.jpg"
Content-Type: image/jpeg


------WebKitFormBoundaryUPRimTCAEA2P1c38
Content-Disposition: form-data; name="mtime[]"

1502566923
------WebKitFormBoundaryUPRimTCAEA2P1c38--

$_POST:

array(3) {
  ["cmd"]=>
  string(6) "upload"
  ["current"]=>
  string(5) "l1_Lw"
  ["mtime"]=>
  array(1) {
    [0]=>
    string(10) "1502566923"
  }
}

$_FILES:

array(1) {
  ["upload"]=>
  array(5) {
    ["name"]=>
    array(1) {
      [0]=>
      string(8) "dims.jpg"
    }
    ["type"]=>
    array(1) {
      [0]=>
      string(10) "image/jpeg"
    }
    ["tmp_name"]=>
    array(1) {
      [0]=>
      string(14) "/tmp/phpNerajj"
    }
    ["error"]=>
    array(1) {
      [0]=>
      int(0)
    }
    ["size"]=>
    array(1) {
      [0]=>
      int(380015)
    }
  }
}

Request body:

array(0) {
}

It works with 2.1.26 without any problem.

@nao-pon
Copy link
Member

nao-pon commented Aug 15, 2017

"current" is included in the parameter. Are you using the APIv1 connector? Which connector?

@bitbybit
Copy link
Author

bitbybit commented Aug 15, 2017

I am using PHP connector from composer:

$elfinder = new \elFinderConnector(new \elFinder([
    'locale' => 'ru_RU.UTF-8',
    'bind' => [
        /**
         * Smart logger function
         * Demonstrate how to work with elFinder event api
         *
         * @param  string   $cmd       command name
         * @param  array    $result    command result
         * @param  array    $args      command arguments from client
         * @param  elFinder $elfinder  elFinder instance
         * @return void|true
         * @author Troex Nevelin
         **/
        'mkdir mkfile rename duplicate upload rm paste put' => function($cmd, $result, $args, $elfinder) use($logger) {
            $log = sprintf('[%s] ID: %s (%s) %s:', date('r'), (($logger['user'] != 'anon.') ? $logger['user']->getUsername() : 'ANONYMOUS'), $logger['ip'] , strtoupper($cmd));
            foreach($result as $key => $value) {
                if(empty($value)) {
                    continue;
                }
                $data = [];
                if(in_array($key, ['error', 'warning'])) {
                    array_push($data, implode(' ', $value));
                } else {
                    if(is_array($value)) { // changes made to files
                        foreach ($value as $file) {
                            $filepath = (isset($file['realpath']) ? $file['realpath'] : $elfinder->realpath($file['hash']));
                            array_push($data, $filepath);
                        }
                    } else { // other value (ex. header)
                        array_push($data, $value);
                    }
                }
                $log .= sprintf(' %s(%s)', $key, implode(', ', $data));
            }
            $log .= "\n";
            if($fp = @fopen($logger['file'], 'a')) {
                fwrite($fp, $log);
                fclose($fp);
            }
        },
    ],
    'roots' => [[
        'driver' => 'LocalFileSystem',
        'path' => $app->getRootDir().$app['config']['dir']['upload_path'].'/',
        'attributes' => [
            [
                'pattern' => '/^\/promo/',
                'read' => false,
                'write' => false,
                'locked' => true,
                'hidden' => true,
            ],
        ],
        'URL' => $request->getScheme().'://'.$request->getHost().'/'.$app['config']['dir']['upload_name'].'/',
        'tmbPath' => $app->getRootDir().$app['config']['dir']['elfinder_cache']['tmb']['path'],
        'tmbURL' => $request->getScheme().'://'.$request->getHost().$app['config']['dir']['elfinder_cache']['tmb']['url'],
        'quarantine' => $app->getRootDir().$app['config']['dir']['elfinder_cache']['quarantine'],
        'copyFrom' => false,
        'copyTo' => false,
        'uploadDeny' => ['all'],
        'uploadAllow' => ['image', 'application/vnd.oasis.opendocument.text', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
        'uploadOrder' => ['deny', 'allow'],
        /**
        * @param string $attr attribute name (read|write|locked|hidden)
        * @param string $path file path relative to volume root directory started with directory separator
        * @return bool|null
        **/
        'accessControl' => function($attr, $path, $data, $volume) {
            return strpos(basename($path), '.') === 0 // if file/folder begins with '.' (dot)
            ? !($attr == 'read' || $attr == 'write')  // set read+write to false, other (locked+hidden) set to true
            : null;                                   // else elFinder decide it itself
        },
        'acceptedName' => function($name) {
            if(mb_substr($name, -4, null, 'UTF-8') === '.php') {
                return false;
            } else {
                return strpos($name, '.') !== 0;
            }
        },
        'disabled' => ['netmount', 'help'],
    ]],
]));

$elfinder->run();

Actually I do not remember when I started to use elFinder but I think it was already verison 2.

@nao-pon
Copy link
Member

nao-pon commented Aug 15, 2017

Ok, Please remove transport : new elFinderSupportVer1() from client configuration.

@bitbybit
Copy link
Author

I do not have such option:

$elfinder.elfinder({
    url: elf.url,
    soundPath: '/editor/elfinder/sounds/',
    lang: 'ru',
    height: 600,
    ui: ["toolbar","path","stat"],
    allowShortcuts: false,
    sync: 10,
});

I have several handlers, commandsOptions and getFileCallback. But I removed all of them and nothing changes.

@nao-pon
Copy link
Member

nao-pon commented Aug 16, 2017

Umm... Which version of "protocol version" in help dialog?

170816-095835

@bitbybit
Copy link
Author

bitbybit commented Aug 16, 2017

_001

Can it be because of an older version of jQuery?
Edited: same result with jQuery/jQuery UI: 3.2.1/1.12.1

Still works with 2.1.26:
_001

{"added":[{"isowner":false,"ts":1502884868,"mime":"image\/jpeg","read":1,"write":1,"size":"380015","hash":"l1_ZGltcy5qcGc","name":"dims.jpg","phash":"l1_Lw","tmb":1,"url":"..."}],"removed":[],"changed":[{"isowner":false,"ts":1502884858,"mime":"directory","read":1,"write":1,"size":0,"hash":"l1_Lw","name":"promo","rootRev":"","options":{"path":"","url":"...","tmbUrl":"...","disabled":["back","forward","netmount","mkdir","mkfile","copy","paste","cut","edit","extract","archive","zipdl","chmod"],"separator":"\/","copyOverwrite":1,"uploadOverwrite":1,"uploadMaxSize":9223372036854775807,"uploadMaxConn":3,"uploadMime":{"firstOrder":"deny","allow":["image"],"deny":["all"]},"dispInlineRegex":"^(?:(?:image|video|audio)|(?:text\/plain|application\/pdf)$)","jpgQuality":100,"archivers":{"create":[],"extract":[],"createext":[]},"uiCmdMap":[],"syncChkAsTs":1,"syncMinMs":10000,"i18nFolderName":0,"tmbCrop":1,"csscls":"elfinder-navbar-root-local"},"volumeid":"l1_","locked":1,"isroot":1,"phash":""}]}

@nao-pon
Copy link
Member

nao-pon commented Aug 16, 2017

❔ It is very strange...

Would you show the response of the initial request (cmd=open&target=&init=1&tree=1)?

Is there a problem elFinder located in the public place? Please let me know the URL if it is open.

@bitbybit
Copy link
Author

I guess I found the reason.

Error:

$elfinder = new \elFinderConnector(new \elFinder([
    'locale' => 'ru_RU.UTF-8',

Uploaded ok:

'locale' => 'en_US.UTF-8'

🤔

@nao-pon
Copy link
Member

nao-pon commented Aug 16, 2017

OK, Please try edit elFinder.class.php L.1287 '%.1f%03d' to '%.1F%03d'

$result['api'] = sprintf('%.1f%03d', self::$ApiVersion, self::$ApiRevision);

to

$result['api'] = sprintf('%.1F%03d', self::$ApiVersion, self::$ApiRevision);

@bitbybit
Copy link
Author

It solves the problem 👍

@nao-pon
Copy link
Member

nao-pon commented Aug 16, 2017

Yes! @bitbybit Thank you so much! 👍 I'll fix it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants