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

prevent overwriting if uploaded file already exists #138

Closed
crispyduck00 opened this issue Mar 12, 2019 · 3 comments
Closed

prevent overwriting if uploaded file already exists #138

crispyduck00 opened this issue Mar 12, 2019 · 3 comments

Comments

@crispyduck00
Copy link

crispyduck00 commented Mar 12, 2019

When a file is uploaded which name already exists, the existing file is overwritten without any warning.

To prevent overwriting existing files a (n) can be added to the filename of the newly uplodad file. Where n is a ongoing number starting with 0.

So for example if "file.zip" exists already in the upload path, rename the newly uploaded "file.zip" to "file (0).zip". If again the same filename is uploaded, rename it to "file (1).zip and so on.

This could be easylie archifed by adding following code bevore the "move_upload_file()" function:

     if(file_exists ($fullPath)) {
          $newPath = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fullPath) . ' (0).' . $ext;    	
          $n = 1;
          while(file_exists ($newPath)) {
                $newPath = preg_replace('/\\.[^.\\s]{3,4}$/', '', $fullPath) . ' (' . $n . ').' . $ext;
                $n++;
          }
          $fullPath = $newPath;
    }

regards,
crispyduck

prasathmani pushed a commit that referenced this issue Mar 13, 2019
@prasathmani
Copy link
Owner

@crispyduck00 , added your suggestion. check with latest.

@crispyduck00
Copy link
Author

crispyduck00 commented Mar 13, 2019

@prasathmani , great solution simply adding the date!
Maybe $datetime_format without dot and spaces can be used for it.
What happens if the filename length exceeds the filesystem limit?

Maybe there should be a configurable filename limit for uploads:
like this

Thanks!

@hedwiggggg
Copy link

It would be nice, if this feature is configurable; So we can turn it off and it actually overwrites the files.

@ivavid ivavid mentioned this issue Feb 14, 2020
ner00 pushed a commit to ner00/tinyfilemanager that referenced this issue May 7, 2023
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