NetTalk Central

Author Topic: upload and rename multiple images  (Read 6171 times)

olu

  • Sr. Member
  • ****
  • Posts: 352
    • View Profile
    • Email
upload and rename multiple images
« on: May 15, 2011, 12:10:58 PM »
I have a window where by i have to upload four different pictures and rename them, the problem is it is renaming them but to the name of the last uploaded file there by only uploading the last file when i click on save on the form.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: upload and rename multiple images
« Reply #1 on: May 15, 2011, 10:00:35 PM »
I'm not sure what you mean Olu.
Perhaps post an example.

cheers
Bruce

olu

  • Sr. Member
  • ****
  • Posts: 352
    • View Profile
    • Email
Re: upload and rename multiple images
« Reply #2 on: May 16, 2011, 12:16:38 AM »
hi bruce have modify example 26 look at the codes in windowhandler for renaming . All am trying to do is get it to rename the uploaded pictures and pt them in a folder of my choice that has been pre-defined but at the moment it rename everything to the last uploaded file.

[attachment deleted by admin]

charl99

  • Full Member
  • ***
  • Posts: 185
    • View Profile
    • Email
Re: upload and rename multiple images
« Reply #3 on: May 16, 2011, 01:45:47 AM »
Hi Olu,

I did not look at your erxample, but this is how I do it.

Define fil:name1, fil:name2, etc.

Then in the PostInsert 1 Start Embed point, code like he following (not my finest piece of code but I was in a hurry:

  if TH:Location <> ''
    l:name = p_web.GSV('fil:name')
    k# = int(TH:ImageNo / 50000)+1
    copy(p_web.gsv('PATH') & '\web\'&clip(l:name),'\\'&clip(GLOD:Server)&'\eds\HD' & k# &'\'&left(format(TH:ImageNo,@n_8))&clip(ExtType))
    remove(p_web.gsv('PATH') & '\web\'&clip(l:name))
  .

  l:name = p_web.GSV('fil:name2')
  l:desc = p_web.GSV('Desc2')

  TH:Memo = ''
  if l:name <> '' and l:desc <> ''
    TH:TicketNo = p_web.GSV('T:TicketNo')
    TH:Desc = l:desc
    k# = len(clip(l:name))
    ExtType = sub(l:desc,k#-4,4)
    TH:ImportDate_Date = today()
    TH:Location = clip(l:name)
    access:THistory.usefile()
    access:THistory.tryinsert()

    k# = int(TH:ImageNo / 50000)+1
    copy(p_web.gsv('PATH') & '\web\'&clip(l:name),'\\'&clip(GLOD:Server)&'\eds\HD' & k# &'\'&left(format(TH:ImageNo,@n_8))&clip(ExtType))
    remove(p_web.gsv('PATH') & '\web\'&clip(l:name))

  .

  l:name = p_web.GSV('fil:name3')
  l:desc = p_web.GSV('Desc3')

  if l:name <> '' and l:desc <> ''
    TH:TicketNo = p_web.GSV('T:TicketNo')
    TH:Desc = l:desc
    k# = len(clip(l:name))
    ExtType = sub(l:desc,k#-4,4)
    TH:ImportDate_Date = today()
    TH:Location = clip(l:name)
    access:THistory.usefile()
    access:THistory.tryinsert()

    k# = int(TH:ImageNo / 50000)+1
    copy(p_web.gsv('PATH') & '\web\'&clip(l:name),'\\'&clip(GLOD:Server)&'\eds\HD' & k# &'\'&left(format(TH:ImageNo,@n_8))&clip(ExtType))
    remove(p_web.gsv('PATH') & '\web\'&clip(l:name))

  .
Cheers
Charl

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: upload and rename multiple images
« Reply #4 on: May 18, 2011, 02:19:03 AM »
Your form has 3 upload fields. Mai:MailBoxPicture,  Mai:MailBoxPicture2 and Mai:MailBoxPicture3.

Ok, so in the WebHandler procedure in the RenameFile method you've added the following two lines of code.

Code: [Select]
   self.site.UploadsPath = clip(self.site.WebFolderPath) &'\uploads\'& SELF.GetSessionValue('talentpicture')
   ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname')&'.jpg')

both lines can appear before the generated Parent call, and since there's no need to then call the Parent call again (since your second line does it) you can add in

Code: [Select]
   RETURN ReturnValue
as well.

Your two lines are being called 3 times for each Post. Each time the p_name parameter tells you which field is being saved, and p_filename is the name of the file being received from the browser.

Notice though that your line ignores both these parameters, instead saving all three pictures to the same name;

Code: [Select]
ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname')&'.jpg')
If you want it to be saved to three different names, then I recommend you use the p_name, or p_filename parameters as part of the name you are saving as.

Cheers
Bruce

olu

  • Sr. Member
  • ****
  • Posts: 352
    • View Profile
    • Email
Re: upload and rename multiple images
« Reply #5 on: May 18, 2011, 07:58:19 AM »
hi bruce please can you modify the posted example to show how to achive this because am abit unclear about your explanation please.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: upload and rename multiple images
« Reply #6 on: May 18, 2011, 10:44:58 PM »
I was using the example in Clarion 8 - not sure how useful that is to you.

Do you understand that the following line which you've got, saves _every_ incoming image with exactly the same name?

ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname')&'.jpg')

ie you are setting all incoming images to talentname.jpg
(where talentname = GSV('talentname')

If you want them to have different names, well then you kinda need to give them different names.

Perhaps the starting point is to determine why you think the above line will give them different names?

cheers
Bruce

olu

  • Sr. Member
  • ****
  • Posts: 352
    • View Profile
    • Email
Re: upload and rename multiple images
« Reply #7 on: May 18, 2011, 11:51:08 PM »
thank bruce i understand that i need to give them different names but even if i do how do i get the rename procedure to execute them individually?
And when you mentioned above to include p_name or p_filename in the new name what do you mean? 

olu

  • Sr. Member
  • ****
  • Posts: 352
    • View Profile
    • Email
Re: upload and rename multiple images
« Reply #8 on: May 19, 2011, 01:45:52 AM »
thanks bruce for the nodge in the right direction abit slow in getting but got there at the end.
Got it to work by doing something like this

If p_name ='MAI:MailBoxPicture'
      ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname')&'.jpg')
   elsif p_name='MAI:MailBoxPicture2'
      ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname2')&'.jpg')
   elsif p_name='MAI:MailBoxPicture3'
      ReturnValue = PARENT.RenameFile(p_name,Clip(self.site.UploadsPath)&'\'& SELF.GetSessionValue('talentname3')&'.jpg')
    End