We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15362
    • 22 Posts
    Hello all,

    When i upload an image and the filename allready exist, my old image replaced with the new one instead of rename it to filename(1).jpg for example.

    Is there any setting that can do this?

    Thanks
      • 27708 MODX Staff
      • 2,502 Posts
      I believe this is normal behaviour of a server. I am sure it's something that could be added to the file browser in whichever version of MODX you are using but for now, there is no setting to check for duplicate file names.
        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 46886
        • 1,154 Posts
        What are you uploading the image with? What tool? Or do you mean uploading from within the manager?
          • 15362
          • 22 Posts
          I am uploading images from TV.
            • 27708 MODX Staff
            • 2,502 Posts
            That functionality would need to be submitted as a feature request at GitHub to alter the functionality of the TV behavior or possibly file uploads in general. Currently, it's essentially just a file upload field that doesn't do much in the way of validation other than file types and size limits. It could be a good feature to check if a file with the identical file name exists, and if so, to rename or append with some index number if it's deemed valuable.
              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 46886
              • 1,154 Posts
              Its normal behavior for modx, so you will need a package or script to handle this I think. Some sort of photomanager to allow for renaming. There are many available, I recently was directed to Jasny's bootstrap http://jasny.github.io/bootstrap/2.3.1/ which I *think* includes photo management, at least that's how I got there.
                • 15362
                • 22 Posts
                So i guess the client with 30 000 articles has to remember the names of the images that he already upload sad

                any plugin with date prefix or something?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  An event OnBeforeFileUpload has been suggested. Right now all there is is the OnFileManagerUpload event, but that is evoked after the file is uploaded and moved into place.

                  From the core/model/modx/sources/modfilemediasource.class.php file
                              if (!move_uploaded_file($file['tmp_name'],$newPath)) {
                                  $this->addError('path',$this->xpdo->lexicon('file_err_upload'));
                                  continue;
                              }
                          }
                  
                          /* invoke event */
                          $this->xpdo->invokeEvent('OnFileManagerUpload',array(
                              'files' => &$objects,
                              'directory' => $container,
                              'source' => &$this,
                          ));
                  

                  An OnBefore... event could be added just before the move_uploaded_file() function call, so then a plugin could do things like check for an existing file of the same name and modify the name to save the file by.

                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 21739
                    • 49 Posts
                    I've been meaning to give the solution posted in this (ancient) thread a try myself - https://forums.modx.com/thread/77844/upload---do-not-overwrite-files-with-the-same-file-name
                    Although 'hacking' the core isn't the nicest way, it sounds like it could provide a temporary solution.

                      • 13218
                      • 134 Posts
                      If possible I usually try to provide a dynamic media source that automatically creates a folder, for each resource. In this way the client doesn't have to manage any kind of folder structure for the uploads, each resource only sees files that are directly connected to it. This can usually also be indroduced in existing setups, I would think.
                        @itWilllBeOK