3 Replies Latest reply on May 2, 2008 3:23 AM by Günter Schenk

    File Upload File Renaming

      I was wondering if anyone knows how to set up a trigger to automatically rename a file on upload to change spaces into underscores using DToolbox image and resize feature. An example is from "My picture.jpg" to "My_picture.jpg". I also wonder if this could be part of a form validation? Maybe using a spry widget?

      I have no experience with triggers, and especially the adobe tng.FileUpload.class.php file (which I assume is where to change the trigger? or maybe it's in the tng.ImageUpload.class.php file?)

      Thanks for the help!

      -Chris
        • 1. Re: File Upload File Renaming
          Günter Schenk Level 4
          Hi Chris,

          fotunately I already made such a modification to ADDT´s predecessor "MX Kollection", and as the core files didn´t change, it will assumingly work the same:

          1. add the following function to the file "includes/common/KT_functions.inc.php":

          /*
          replace all chars from uploaded filenames other than alpha-numeric and "_" and "-" and "." with an underscore (_)
          */

          function KT_websafe_filename($text) {
          return preg_replace("/[^a-zA-Z0-9\-_\.]+/", "_", $text);
          }

          2. change line 120 in file "includes/common/lib/file_upload/KT_FileUpload.class.php":

          old: $fileName = KT_replaceSpecialChars($fileName, 'filter');
          new: $fileName = KT_websafe_filename($fileName, 'filter');

          This modification will of course *always* be renaming the uploaded file accordingly -- but you´ll need no fancy trigger and anything else.

          Please backup the 2 original files !!

          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: File Upload File Renaming
            Level 1
            only, it's actually on line 220 and not 120:)

            thanks so much ! you've saved me a lot of work.
            • 3. Re: File Upload File Renaming
              Günter Schenk Level 4
              -----
              it's actually on line 220 and not 120:)
              -----

              see, one year ago when I wrote the reply, the code *was* on line 120 -- but within that year it has apparently moved downwards due to gravitational force :-)

              Cheers,
              Günter Schenk
              Adobe Community Expert, Dreamweaver