16 Replies Latest reply on Nov 28, 2007 11:46 AM by Günter Schenk

    Upload file with versioning?

    Level 1
      I am trying to create a site that using file versioning and am not sure how best to do it. I have very limited experience with the file upload tools. What I am looking for is for users to be able to login and then upload a file for a project and then have that page list all the files that have been uploaded as well as the date they were uploaded so the other users can choose which they want to download. I am not sure if the file names would cause trouble if they are different. Something like this I am thinking:

      Project 1:
      File1.doc 9/1/07 5:56am
      File1(1).doc 9/1/07 7:00am
      File1done.doc 9/2/07 8:22pm

      Project 2:
      File2.doc 11/25/07 5:00pm
      File2edited.doc 11/26/07 7:00am

      Is this possible?

      Thanks!
      -Dan
        • 1. Re: Upload file with versioning?
          Günter Schenk Level 4
          Hi Dan,

          -------
          have that page list all the files that have been uploaded as well as the date they were uploaded
          -------

          just implement ADDT´s "File List Recordset" behaviour (see under "File Upload") on whatever page -- this one will also display the file´s creation date on the server.

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Upload file with versioning?
            Level 1
            Thanks for the pointer Günter - I guess my question has to deal with how to upload files then. I am looking for a way to upload multiple versions of the same file. I cannot get the database to store multiple names for each version of the file. It only has one field, ideally I would like to use another table to store the fileid, projectid, and filename and location.

            Any ideas on what I might be doing wrong?

            Thanks,
            -Dan
            • 3. Re: Upload file with versioning?
              Level 1
              I should probably be more clear - what happens is that only the last file uploaded is kept on the server (in the correct folder though). I have a custom renaming rule on that incorporates the file name so I am not sure why the older ones are just deleted if a different filename is chosen. I tried incorporating the current date and time into the filename but the "/" generates errors.

              How can I set the upload to keep all files and if there is a duplicate just add a (1) or (2), etc. to the end? I would also like the file renaming rule to incorporate the user's name (session variables) who uploaded it.
              • 4. Re: Upload file with versioning?
                Level 1
                Sorry for the amount of replies - I was able to get it to work - I just needed to set the database field to None: Custom Rename. Took a while to try all the possible combos of settings but it seems to be working now.

                Thanks again,
                -Dan
                • 5. Re: Upload file with versioning?
                  Level 1
                  Hi Günter,
                  One more question if you don't mind. I have it mostly working but there is a problem when uploading a file with the same filename.

                  Is there any way to alter the upload behavior with custom renaming to append either a random number, the time, or 1, 2, 11, etc. to the end if the filename is a duplicate instead of throwing back an error saying that the file already exists?

                  I see a previous post from you on the old Interaktonline boards (http://www.interaktonline.com/Products/Bundles/MXKollection/Product-Forum/Details/115536 /Rename+file+on+upload.html) where you removed spaces, is there a way to do a similar modification to throw on a sequential number at the end?

                  Thanks for all your help again on this!
                  Dan
                  • 6. Re: Upload file with versioning?
                    Günter Schenk Level 4
                    Hi Daniel,

                    AFAIK, when using the Automatic Renaming option, ADDT will append "_1", "_2" etc etc (means, an incremental number) to the newly uploaded file´s name anyway

                    Cheers,
                    Günter Schenk
                    Adobe Community Expert, Dreamweaver
                    • 7. Re: Upload file with versioning?
                      Level 1
                      Is there a way to combine that with the custom naming masks as well? Right now I am adding the user's name to the beginning of each file.
                      • 8. Re: Upload file with versioning?
                        Günter Schenk Level 4
                        Hi Dan,

                        --------
                        Is there a way to combine that with the custom naming masks as well?
                        --------

                        that´s not possible.

                        --------
                        Right now I am adding the user's name to the beginning of each file
                        --------

                        what about creating a custom renaming rule that´s..

                        a) preceeding the file name with the user name (good idea BTW), and

                        b) adding one of ADDT´s "dynamic data" after the file name ? What could be a reasonable idea in your case, were using {now_dt}, means the current date + time, what´s of course always be warranting a unique file name.

                        Cheers,
                        Günter Schenk
                        Adobe Community Expert, Dreamweaver
                        • 9. Re: Upload file with versioning?
                          Level 1
                          I tried using the {now_dt} earlier but it gave me an error with the /s that were being used to display the other dates on the site. Is there a way to get {now_dt} to use the database format instead of the display format? Or would it just be easier to reformat all the other instances of the date that appear on the site and set the settings to not use any slashes?
                          • 10. Re: Upload file with versioning?
                            Günter Schenk Level 4
                            -------
                            Is there a way to get {now_dt} to use the database format instead of the display format?
                            -------

                            no, but it´s actually possible to add custom-made "dynamic data" formats to the file includes/common/KT_functions.inc.php, and I have done just that for at least adding the current date as MySQL format (YYYY-MM-DD) to the file name.

                            Here´s how it works:

                            1. open "KT_functions.inc.php" and search for the line:
                            // DynamicData functions - use this to define more functions

                            2. further below you´ll see ADDT´s predefined dynamic data instances:

                            $date_now =...
                            $date_dt_now =...
                            $date_t_now =...

                            add the line:
                            $date_now_db_date = KT_convertDate(date('Y-m-d'), "yyyy-mm-dd", $GLOBALS['KT_db_date_format']);

                            below

                            3. further below you´ll see an array starting with:
                            $dynamicDataFunctions = array(

                            somewhere in between you can add...

                            'NOW_DB()' => $date_now_db_date,
                            'now_db()' => $date_now_db_date,
                            'NOW_DB' => $date_now_db_date,
                            'now_db' => $date_now_db_date,

                            to make ADDT handle your own DynamicData - type {NOW_DB}

                            Well, as you surely might rather want to use both ADDT´s $GLOBALS['KT_db_date_format'] and the $GLOBALS['KT_db_time_format'] in order to generate a truly unique file name, we should try and find a way to add yet another DynamicData - type which comprises both elements, as the date alone will not be sufficient to tell one file version from the other -- one indication for how this could be done, is the existing "$date_dt_now" variable, because this one sort of concatenates two ADDT $GLOBALS['whatever'] variables.

                            I have thought about this for quite a while -- guess it´s time to finally get it implemented :-)

                            Cheers,
                            Günter Schenk
                            Adobe Community Expert, Dreamweaver
                            • 11. Re: Upload file with versioning?
                              Level 1
                              Awesome - thanks - that is doing it. And I am close on getting the time in there too but not quite - the last digits of the time change in unpredictable ways. If they are seconds then it would appear the minutes never advance. I am just not really sure what numbers I ended up pulling - I though it would just be the time in Hours-minutes-seconds. What I did was use this instead:

                              $date_now_db_date = KT_convertDate(date('Y-m-d H:i:s'), "yyyy-mm-dd H-i-s", $GLOBALS['KT_db_date_format'].'-' .$GLOBALS['db_time_format_nc']);

                              in the DynamicData functions part and then added this:

                              $GLOBALS['db_time_format_nc'] = str_replace(':', "-", $GLOBALS['KT_db_time_format']);

                              further down the page under "function KT_getInternalTimeFormat() {".

                              Any idea where I'm going wrong?
                              • 12. Re: Upload file with versioning?
                                Günter Schenk Level 4
                                Hi Dan,

                                how about making the new variable "$date_now_db_date" just apply the "str_replace" to the already existing "$date_dt_now" variable:

                                $date_now_db_date = str_replace(':', "-", $date_dt_now);

                                If I´m not completely wrong, this should work ;-)

                                Cheers,
                                Günter Schenk
                                Adobe Community Expert, Dreamweaver
                                • 13. Re: Upload file with versioning?
                                  Level 1
                                  Haha, yeah, that would be easier! At first I was getting an error about /s but I replaced those with dashes as well. Now it is ok but the time is coming out hours-minutes AM or PM. I am sure this has to do with that being the way I am displaying times normally. This probably will not be a problem (I'm not expecting anyone to upload a file twice in 60 seconds, but it would be nice to get the seconds in there as well. Every time I try though I can't seem to get it to come out right.
                                  • 14. Re: Upload file with versioning?
                                    Günter Schenk Level 4
                                    Great ! That´s at least a huge step in the right direction :-)

                                    Well, I honestly wonder if it´s really required to pass your "$date_now_db_date" variable through ADDT´s "KT_convertDate" function, or if it wouldn´t be enough to assign it a PHP date() function containing the formatting you prefer, like:

                                    $date_now_db_date = date('Y-m-d__H-i-s');

                                    How about that, does it work ?

                                    Cheers,
                                    Günter Schenk
                                    Adobe Community Expert, Dreamweaver
                                    • 15. Re: Upload file with versioning?
                                      Level 1
                                      That did it! Thanks - easiest method yet and it works perfect!

                                      Thanks again!
                                      • 16. Re: Upload file with versioning?
                                        Günter Schenk Level 4
                                        HA ! :-)

                                        Cheers,
                                        Günter Schenk
                                        Adobe Community Expert, Dreamweaver