Skip to main content
Known Participant
May 5, 2009
Question

looping through form and uploading files?

  • May 5, 2009
  • 1 reply
  • 924 views

Hi,

I have 4 upload fields in my form. I want to submit the form, loop through the fileds and upload them to my folder. Below is what I have so far.

Can anyone show me how this is done?

<cfif isDefined('submit')>
<cfloop index="x" list="#form.fieldnames#">
<cfoutput>
#x# - #form#<br></cfoutput>
<cffile action="upload" nameconflict="overwrite"  destination="#ExpandPath("#application.rankingsFolder#")#" filefield="form" />

</cfloop>
</cfif>

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 5, 2009

    You're on the right track.  Two more steps and you should be there.

    1.  Put some if/else logic inside your loop to check that x represents a form file field, and that a file exists.

    2.  This, <cfoutput>#form#</cfoutput> will probably crash for a file.  I've never actually tried it though.

    HulfyAuthor
    Known Participant
    May 5, 2009

    I have been staring at it and it is not really making any sense this is what form dumps out, the list of fieldnames and the values. How can I compare each value to see if it has a file and then uploadthe file? Also how can I distinguish the list of fieldnames from the actual fields and why is this in here?

    How does the struct sore the values? #form.club# or link and array #form[0]#

    <cfloop collection="#form#" item="#fieldname#">
                
                 <cfoutput>#fieldname#</cfoutput>         
       </cfloop>
      </cfif>

    CLUB[empty string]
    FIELDNAMESMAIN,SENIOR,CLUB,JUNIOR
    JUNIOR[empty string]
    MAIN/Applications/ColdFusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp/neotmp39739.tmp
    SENIOR

    [empty string

    ilssac
    Inspiring
    May 5, 2009

    MAIN:  /Applications/ColdFusion8/runtime/servers/coldfusion/SERVER-INF/temp/wwwroot-tmp /neotmp39739.tmp

    This is the file field and the output is the file location of the temporary file where the web server put it file content after it received it from the browser.  This is what you would need to look for, a file path.