• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 699
  • Last Modified:

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 -


0
jramos74
Asked:
jramos74
1 Solution
 
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

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now