NetTalk Central

Author Topic: Repost: Folder location and file renaming  (Read 2774 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Repost: Folder location and file renaming
« on: April 29, 2010, 11:39:59 PM »
I am reposting this because I can see the original posting on the home page but not in this forum

Clarion 6.3 Windows XP Nettalk 4.46 /Nettalk5 pr11
When I upload files I need to do 2 things
1. Specify what folder under the web I want the file to be stored in
2. Rename the file to correspond with the unique ID of the record to which it is attached.

In respect of 1 I thought to set a session variable to a value in the form and in the webserver Rename File embed point set the name of the folder based on the session variable value but didn't manage to get anything to work.

I would appreciate any pointers to these 2 issues
Thanks
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

bwhisler

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: Repost: Folder location and file renaming
« Reply #1 on: April 30, 2010, 02:36:29 AM »
First off a warning, I'm rather new at this myself<g>.

However with that said, what I have done to accomplish this is to use something like the following in the WebHandler Rename method:

    ! Rename UPLOAD FILE
    ! RenameFile PROCEDURE(STRING p_name,STRING p_filename,<String p_path>)
    !----------------------------------------------------------------------
    ! Set target based on source
    !----------------------------------------------------------------------
    CASE LOWER(p_Name)
    OF 'filemanageruploadname'
        !------------------------------------------------------------------
        ! FileManager Upload
        !------------------------------------------------------------------
        NewPath = GLO:WebPath & '\' & Self.GSV('CT:FilesLoc')
        self.site.UploadsPath = NewPath
        p_filename = self.GSV('CT:SaveFileName')
    END

In the GenerateForm of the procedure that contains the upload field, I set the Session Variable "CT:FilesLoc" to where I want the file to be stored relative to the "Web" folder. Then in the above code I retrieve that value and prefix it with the path to the Web Folder in order to get a full qualified file path. A separate session variable contains the name as I want it to be stored, in this case the variable is "CT:SaveFileName".

Since I have multiple locations that might upload a file, I make sure each one has a unique name for the upload field as well as unique session variables for passing information.

So far this seems to be working for me but maybe someone else has a better approach.

Barton

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Repost: Folder location and file renaming
« Reply #2 on: April 30, 2010, 03:03:38 AM »
Thanks barton, I'll definitely give it a try.
Any ideas on the renaming of the uploaded file to another name? Problem is that if I let them use any old name there could be a conflict and one of the records will be displaying the incorrect attached file.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kashiash

  • Newbie
  • *
  • Posts: 48
    • View Profile
    • Email
Re: Repost: Folder location and file renaming
« Reply #3 on: April 30, 2010, 03:15:43 AM »
try to create name using date time and session number
if uploaded file is related to a record ina some table then you can use also record id for file name

bwhisler

  • Newbie
  • *
  • Posts: 33
    • View Profile
    • Email
Re: Repost: Folder location and file renaming
« Reply #4 on: April 30, 2010, 03:26:57 AM »
The p_filename contains the name that the user gave however you can change it to anything that you want. To make sure it is unique, just add a date and time to the name.

Or alternatively you can set the name that you want to use before they even upload it and save it into a session variable like "CT:SaveFileName" in my prior example. Then regardless of what they call it, it will be save with your name.

You can also using EXISTS() in the rename method to check to see if a file already exist and if so, modify it by appending a number or something else until it is unique.

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Repost: Folder location and file renaming
« Reply #5 on: May 06, 2010, 10:23:10 PM »
My question is specifically which embed do I put the code in.
As an example:
If the uniqueid of the record in which I am uploading the file is 1234 and I upload a file called terry.gif after upload I want to rename that file to 1234.gif, move it to a folder and update my record field in the record to 'foldername/1234.gif'
1. In which embed point do I do this
2. Any example code showing the principles would be appreciated.
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11193
    • View Profile
Re: Repost: Folder location and file renaming
« Reply #6 on: May 06, 2010, 11:14:17 PM »
Hi Terry,

probably a good place is in the ValidateRecord embed in the form. - ie in the ValidateRecord routine in the frm.

Cheers
Bruce