troubleshooting Question

How do I loop through a filecount and upload the correct number of images

Avatar of smfmetro10
smfmetro10Flag for United States of America asked on
ColdFusion Language
2 Comments1 Solution335 ViewsLast Modified:

I have a form with the ability for the user to add file uploads to upload images etc.

It has a hidden file that keeps the filecount.

My problem is that on the upload page only one image is being uploaded to the correct folder.

I've included my code for better clarification

<!--EDIT PAGE-->
function addFile(theBtn){
  var theForm = theBtn.form;
  if(theForm.fileCount.value>=5) return;
  var fileNum = theForm.fileCount.value -= -1;
  var theDiv = theForm.userfile1;
  if(theDiv.length) theDiv = theDiv[0];
  theDiv = theDiv.parentNode;
  var newDiv = theDiv.cloneNode(true);
  var newFile = newDiv.getElementsByTagName("input")[0]; = "userfile"+fileNum; =;
  theBtn.parentNode.insertBefore(newDiv, theBtn)

<cfoutput><form action="insert.cfm?candidatenum=#url.candidatenum# method="post" enctype="multipart/form-data"></cfoutput>
<td width="120">Project Name:</td>
<td width="317"><input type="text" name="txtProjectname1"  size="50"/></td>
<td>Project Description:</td><td><textarea name="txtProjectDesc1" cols="50" rows="5"></textarea></td>
<td>Work Plan:</td><td><input type="file" size="30" name="fleworkplan1" /></td>
<td>Work Samples:</td><td><input type="hidden" name="fileCount" value="1" />

<input type=file name="userfile1"  size="20" />

<input type=button value="Add" onClick="addFile(this)"></td>


<td><input type="submit" name="submit" value="Save and Review" /></td><td colspan="2"><input style="display:none" id="btnSubmit" type="submit" value="Submit for Evaluation" name="btnSubmit"><span style="display:inline; vertical-align:top" id="btnSubmitMsg">Check when you are done and ready to submit</span><input name="commission" type="checkbox" value="y" onclick="document.getElementById('btnSubmit').style.display=(this.checked?'inline':'none');document.getElementById('btnSubmitMsg').style.display=(this.checked?'none':'inline')"></td><td width="27" align="left">
<!---If yes, display an alert that they cannot submit and hide the button below. --->



<cfif Form.submit eq "Save and Review">
<cfset thisDir = ExpandPath("./"& url.candidatenum)>
<cfif not directoryExists(thisDir )>
     <cfdirectory action="create" directory="#thisDir #">
<cfset thisDir = ("#thisDir#")>

<cfloop from="1" to="#FORM.fileCount#" index="counter">
      <!--- if this field contains a file ....--->
      <cfif len(form["userfile"& counter])>
            <!--- upload it to the proper folder....--->
            <cffile action="upload" 
                  fileField = "userfile#counter#" 
                 destination = "#thisDir#" 
                 nameConflict = "MakeUnique">
				 <cflocation url="candidate_show.cfm?candidatenum=#url.candidatenum#>				 </cfif></cfloop></cfif>

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros