Uploading Multiple Files with Coldfusion

Posted on 2006-04-25
Last Modified: 2013-12-24
I need help on how to construct uploading multiple files on one submission.

I have the display code as follows:

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

Action File:

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

Thanks -

Question by:jramos74
    1 Comment
    LVL 7

    Accepted Solution

    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#">
    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>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Network it in WD Red

    There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

    Suggested Solutions

    Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
    If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
    The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and Log…
    The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Open Page or Post…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now