Uploading Multiple Files with Coldfusion

I need help on how to construct uploading multiple files on one submission.

I have the display code as follows:

<tr>
  <td colspan="2"><strong>Upload List: </strong> <br>
  <input type="file" name="uploadfile" size="40">
</tr>

Action File:

<cfif isdefined('uploadfile') and uploadfile neq "">
      <cfset uploadpath = 'c:\my schoollist\list\'>
      <cfset subdir = #uploadpath#&#get_list_info.id#&'\'>
      
      <cfif  NOT DirectoryExists(subdir)>
            <cfdirectory action="create" directory="#subdir#">
      </cfif>
      <!--- Upload File --->
      <cffile action="UPLOAD" destination="#subdir#" nameconflict="MAKEUNIQUE" filefield="uploadfile">
</cfif>

Thanks -


jramos74Asked:
Who is Participating?
 
black0psCommented:
1 <cfset numberoffields = 10>
2  <cfif isdefined("form.upload")>
3    <cfset message = "">
4    <cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
5      <cfset filename = "form.file" & #i#>
6      <cfif evaluate(variables.filename) neq "">
7        <cffile action="UPLOAD"
8           destination="c:cfusionmxwwwrootNAPAfiles"
9           nameconflict="OVERWRITE"
10           filefield="#variables.filename#">
11        <cfset message = message & ",File%20#i#%20(#file.serverfile#)%20was%20uploaded">
12      <cfelse>
13        <cfset message = message & ",File%20#i#%20was%20empty">
14      </cfif>
15    </cfloop>
16    <cflocation url="FileUpload.cfm?msg=#variables.message#">
17  
18 <cfelse>
19   <h2>File Upload</h2>20    <cfif isdefined("url.msg")>
21       <div style="color:#FF0000;">
22       <cfloop list="#url.msg#" index="i">
23         <cfoutput>#i#</cfoutput><br />
24       </cfloop>
25       </div>
26    </cfif>
27   <form action="FileUpload.cfm" enctype="multipart/form-data" method="post">
28      <cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
29      <cfset filename = "file" & #i#>
30      <input type="File" name="<cfoutput>#variables.filename#</cfoutput>" /><br />
31      </cfloop>
32  <input type="Submit" name="upload" value="upload">
33  </form>
34 </cfif>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.