On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi,

    probably a common issue but I didn't find a solution when searching the forum...

    Whenever users enter directory names including blanks or german umlauts I run into problems:
    Image upload does not work correctly (found no error message) if umlauts are included.
    phpThumbOf does not like blanks in paths or image names.

    Is there a way to change image names / directory names automatically when created? (Blanks to _ and umlauts ä-->ae or similar)

    I know you should never use those chars in identifiers... but it will be difficult to teach the users not to use them.


    Thanks in advance

    Thomas

    This question has been answered by hochmohr. See the first response.

    [ed. note: hochmohr last edited this post 8 years, 9 months ago.]
      • Revolution 2.2.6
      • I also have this kinds of problems (for 5 years now =D) with my editors, you can tell them 1 Million times, there will always be another case like this^^, so a solution to this problem would be very welcome but it's not so easy I guess (also bc one of the servers I'm "forced" to use is really an as***** when it comes to such filenames...you cannot rename them again, not even with the almighty ftp user^^...) so a solution, at least in my eyes, should be more like client-side validation of the files uploaded into the manager, like when they add a file to the upload window, it should be checked for such "anomalies" and just reject to upload that file...an explanation why would be helpful =D.
        • discuss.answer
          Thanks for your replies,

          I tried the github package... nice idea but it did not work on my system (the image with umlauts was written to a wrong directory before the package was able to rename it).
          So I tried the first guess shown in the discussion... and it worked!
          The only thing I changed for my project is that it will translate the umlauts, so I use the following code (which is not complete yet but a start):

          modfilemediasource.class.php in core/model/modx/sources around line 650

                      if ($size > $maxFileSize) {
                          $this->addError('path',$this->xpdo->lexicon('file_err_too_large',array(
                              'size' => $size,
                              'allowed' => $maxFileSize,
                          )));
                          continue;
                      }
          
          			/////// added / changed lines
                      $pat = array('/Ä/','/Ö/','/Ü/','/ä/','/ö/','/ü/','/ß/', '/(á|â|à)/', '/(é|è|ê)/', '/(í|ì|î)/', '/\s+/');
                      $rep = array('Ae','Oe','Ue','ae','oe','ue','ss', 'a', 'e', 'i', '_');
                      $newPath = preg_replace($pat, $rep, utf8_decode($file['name']));			
                      $newPath = $this->fileHandler->sanitizePath($newPath);
          //            $newPath = $this->fileHandler->sanitizePath($file['name']);
                      ///////
          
                      $newPath = $directory->getPath().$newPath;


          The utf8_decode() may result in more problems... anyway I'll try it.

          Thomas
          • @hochmohr

            was fighting also with german/french umlauts and rewrote/modified the github plugin, code is in this thread:

            http://forums.modx.com/thread/73940/revolution-removing-unwanted-forreign-characters-on-file-upload-that-breaks-stuff-like-phpthumb

            but what do you mean by "is moved to another path before..."? How are your file uploaded? Not by the modx file manager?
            • @exside

              There was a strange behavior when I uploaded an image from within TinyMCE, which should use the standard file upload manager: The file did not show up in the desired folder but in its parent folder. The same image renamed before upload (without umlauts) worked just fine.

              Thomas