Announcement

Collapse
No announcement yet.

Rename file during upload

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rename file during upload

    Hello Forum Members,
    I've a field with datatype Document (File Name). For the specified field I want when the end user upload any file that will automatically renamed according to a global variable. Is it possible? Very much needed.

    Thanks
    Rajibul
    __________________
    S. M. Rajibul Huda
    CEO & Founder
    www.efficienterp.com

  • #2
    Use "rename()" in onAfterInsert/onAfterUpate events.
    /Giuseppe

    Professional Scriptcase Services
    Some Customers opinions

    Comment


    • #3
      Originally posted by Giu View Post
      Use "rename()" in onAfterInsert/onAfterUpate events.
      Hello Giuseppe,

      Thanks for your prompt response. Rename() will rename the file in physical location. Would you please explain it litte bit.

      Thanks

      Rajibul
      __________________
      S. M. Rajibul Huda
      CEO & Founder
      www.efficienterp.com

      Comment


      • #4
        Indeed, the file is first copied to a temporary directory and then moved to the final location. Useually you need to save first to get the job done as the file is not present in the final location after upload is complete. Afaik it's not by default possible to change filenames during the process. If you don't want to dive into the generated code, you need a work-around. What Giuseppe means I think is that after save the file is moved to the final destination. You can change the name then and adapt the new name into the database. You have to do a manual update of the record.
        Albert Drent
        aducom software netherlands
        scriptcase partner, reseller, support and (turn-key) development
        www.scriptcase.eu / www.scriptcase.nl

        Comment


        • #5
          Originally posted by aducom View Post
          Indeed, the file is first copied to a temporary directory and then moved to the final location. Useually you need to save first to get the job done as the file is not present in the final location after upload is complete. Afaik it's not by default possible to change filenames during the process. If you don't want to dive into the generated code, you need a work-around. What Giuseppe means I think is that after save the file is moved to the final destination. You can change the name then and adapt the new name into the database. You have to do a manual update of the record.

          Exactly.

          1.- You upload file and record is saved.
          2.- You obtain path and rename physical file.
          3.- You update your record with the name of the new file.

          I have in my ToDo to create a function to share because this is a commonly question, but as always, lack of time is the problem.
          /Giuseppe

          Professional Scriptcase Services
          Some Customers opinions

          Comment


          • #6
            Got it. Thank you very much Giuseppe and Albert Drent.
            __________________
            S. M. Rajibul Huda
            CEO & Founder
            www.efficienterp.com

            Comment


            • #7
              Hi,
              How can i obtain path directory from document(file name) type ?
              i have tried to search it from forum conversation and still have no clue.

              i have form to change document to the new one.
              it will upload new file, update file name in database,
              and once update done, new file name should be uploaded into doc directory
              and old file name should be removed to archive directory.
              how can i do that ?

              I have tried to use rename() function, but it always failed with reason file not found.
              I think i should get correct directory first to use rename() function.
              please help .....
              appreciate your help on this

              moelath
              Last edited by moelath; 10-15-2014, 09:47 AM.

              Comment


              • #8
                moelath, see the file directory in your Application > file path

                obviously in development environment will be: /wwwroot/scriptcase/file/doc

                in deployment is projectroot/_lib/file/doc (or img) then add the file name

                Comment


                • #9
                  OK, Thanks MikeDE i saw it,
                  Does it mean i hard-coded my directory path during "development phase" ?
                  reading from forum discussion, this "Application > file path" value will be override when we deploy the application (advance mode), is it correct ?
                  if it is true, what should we put in Application > file path before deployment? is it "/_lib/file/doc" ?

                  what happened after the deployment, later on user want to change the directory ?

                  can i put this path into a parameter table ?
                  so, whenever user want to change the path, they just need to update the parameter table value.

                  sorry if i have too many question, i just need to understand how it work ....
                  thanks again

                  Comment


                  • #10
                    Originally posted by moelath View Post
                    Does it mean i hard-coded my directory path during "development phase" ?
                    no, once you deploy it should take the other link automatically /_lib/file/doc, unless you chose advanced deployment and configure otherwise.

                    Originally posted by moelath View Post
                    reading from forum discussion, this "Application > file path" value will be override when we deploy the application (advance mode), is it correct ?
                    it will not override, it will take the path of deployment

                    Originally posted by moelath View Post
                    if it is true, what should we put in Application > file path before deployment? is it "/_lib/file/doc" ?
                    no need, when you are developing, test your applications on development environment using the provided path in Application > file path.... once you deploy (normal deployment) the path will be /_lib/file/... unless you chose it differently during deployment

                    Originally posted by moelath View Post
                    what happened after the deployment, later on user want to change the directory ?
                    not recommended, files will remain on the old path, if you changed the path in second deployment or change field settings then re-deployed, new files will be stored in the new path, hence the older files, if requested by user will not work (since their path is wrong) - why would you do that anyway!? use stable file path, you can use a sub-folder settings as well, then do-it-once-and-forget-it (that is my opinion)

                    Originally posted by moelath View Post
                    can i put this path into a parameter table ?
                    so, whenever user want to change the path, they just need to update the parameter table value.
                    i think so, try onApplicationInIt, define path and use it within code, make few tests, see what happens and let us know (i didn't try this myself)

                    Originally posted by moelath View Post

                    sorry if i have too many question, i just need to understand how it work ....
                    thanks again
                    you are welcome
                    Last edited by MikeDE; 10-15-2014, 11:41 AM.

                    Comment


                    • #11
                      Woww.... Thanks MikeDE,
                      Thanks for your patience to address all my questions. Really appreciate it.
                      And yes, i agree with you, now i also understand why directory name cannot be changed after deployment.

                      And now i also understand, why on other thread, someone creating script to distinguish directory path during development and production as below :
                      -----------
                      // Identify if running on Prod or Dev environment
                      if ((substr($_SERVER['HTTP_HOST'],-4) == '8083') OR (substr($_SERVER['HTTP_HOST'],-4) == '8098')) { // Current Port?
                      [prod] = FALSE;
                      [fp] = "../../../file/doc/timesheets/";

                      } else {
                      [prod] = TRUE;
                      [fp] = "../_lib/file/doc/timesheets/";
                      }
                      --------------
                      Thanks again ...

                      Comment


                      • #12
                        no problem, if you want more about paths, see this post, started with something and then stuck diving with paths earlier
                        http://www.scriptcase.net/forum/show...iving-me-crazy

                        Comment


                        • #13
                          Hello everyone,
                          i need rename() function run in scriptcase for file name change in localhost directory.
                          i have error when run the rename function as "The system cannot find the path specified. (code: 3)".
                          how to set default path for rename function.
                          the following code is given in on validate event.
                          rename("/grp__NM__bg__NM__y5 LOGO1.jpg","bgr.jpg");
                          i have the file in wwwroot directory.

                          Comment


                          • #14
                            MIKEDESAMACHANSEMPAI has become a beast in this =S......

                            Comment


                            • #15
                              Originally posted by kafecadm View Post
                              MIKEDESAMACHANSEMPAI has become a beast in this =S......
                              oh no no boss sempai i didn't work on renaming, actually i'm preparing for you the long list and this is kinda included loool just time doesn't help at all, will be back to you soon... meanwhile if you can help the dude up here please give him a hint, i checked my functions couldn't find something related

                              cheers

                              Comment

                              Working...
                              X