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

Upload files with same filenames will not have normalized name #112

Closed
waifung0207 opened this issue Feb 16, 2017 · 4 comments
Closed

Upload files with same filenames will not have normalized name #112

waifung0207 opened this issue Feb 16, 2017 · 4 comments
Assignees
Milestone

Comments

@waifung0207
Copy link

Config files (both JS and PHP connector) already has "normalizeFilename = true".

Can reproduce issue as follow:

  • upload a file (e.g. "test.png")
  • upload a file with same filename (also "test.png")
  • expected result: either error message, or rename the 2nd file as "test_1.png" etc.
  • actual result: the 2nd file is renamed as "test (1).png", which is not a normalized filename

Please advise whether I can configure this naming logic by changing any file / config.

Thanks very much.

@psolom
Copy link
Owner

psolom commented Feb 16, 2017

All that "normalizeFilename" do is: "Sanitize file/folder name, replaces gaps and some other special chars" (original filename), nothing more. At the moment there are only two possible behaviors:

  1. Overwriting existing file if the one exists with the same name (see "overwrite" option in the config file)
  2. Creating new file with a name supplemented by the postfix: "test.png" turns to "test (1).png"

No capability to fire error message implemented, I could change the format of the postfix though. However what the problem do you have with " (N)" postfix?

@waifung0207
Copy link
Author

Thanks for your prompt reply!

The main problem with " (N)" postfix in my case is, I will further publish the asset to elsewhere via SFTP (phpseclib), which cannot correctly recognize filename with some special characters.

Anyway I have figured out the solution by editing upcount_name_callback() in your /connectors/php/BaseUploadHandler.php file.

I have changed the code from this:

    protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? ((int)$matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return ' ('.$index.')'.$ext;
    }

To this:

    protected function upcount_name_callback($matches) {
        $index = isset($matches[1]) ? ((int)$matches[1]) + 1 : 1;
        $ext = isset($matches[2]) ? $matches[2] : '';
        return '_'.$index.$ext;
    }

Then the file "test.png" will rename "test_1.png" now.

@dereks
Copy link
Contributor

dereks commented Feb 16, 2017

I would also prefer not to have spaces and parentheses inserted into a file name. It makes is more difficult to use a command-line shell with TAB-completion.

@psolom
Copy link
Owner

psolom commented Dec 20, 2017

Released in v2.7.0

@psolom psolom closed this as completed Dec 20, 2017
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

3 participants