Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Upload "n" files 1

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
How can I have ColdFusion create "n" upload boxes and make the necessary changes to the action page. Basically I want a user to be able to select how many files they want to upload from a form and have the form and action pages change accordingly. I'm sure this will require a loop.

Ryan ;-]
 
Hey Ryan,

I'm assuming you'll have no trouble taking the number they want and creating that many file boxes. I'm guessing your question revolves around handling a variable number of variables.

Here's what I would recommend. Inside your loop where you're creating the form, call the file inputs something like "type="file" name="upl#x#" where x is your current count in the loop (from 1 to "n"). You'll then have a form with file boxes named "upl1", "upl2", "upl3",... You can then create a hidden input variable called "numberInputs" and set it equal to the number of file inputs the user requested.

On the submit page, you'll just loop through the inputs and process them one at a time. Something like this should work.

<cfloop index=&quot;x&quot; from=&quot;1&quot; to=#form.numberInputs#>

<cffile action=&quot;upload&quot; fileField=#evaluate(&quot;form.upl#x#&quot;)# ....>

</cfloop>

Hope this helps,
GJ
 
GJ,

You shouldn't assume! Haha, I'm not quite sure how to take a number that the user enters and make that many upload files boxes.

I also don't know exactly how to integrate your loop into the action page.

I'm sorry!

Ryan ;-]
 
Thanks GJ. I ended up getting it to work. The only problem is that now I can't use <CFIF Form.UpFile NEQ &quot;&quot;> to validate if the formfield is empty or not. I tried to use the variable x with it, like this:

<cfloop index=&quot;x&quot; from=&quot;1&quot; to=#form.numberInputs#>
<CFIF Form.UpFile#x# NEQ &quot;&quot;><cffile action=&quot;upload&quot; fileField=&quot;form.upfile#x#&quot; DESTINATION=&quot;#UploadDirectory#\#getUser.UserName#_#datetime#\&quot;
NAMECONFLICT=&quot;MakeUnique&quot;
ACCEPT=&quot;application/pdf,application/msword,text/html,application/vnd.ms-excel,application/vnd.ms-powerpoint,text/plain,image/jpeg,image/pjpeg,image/gif&quot;></cfif>
</cfloop>

ColdFusion says that within the CFIF tag there is invalid syntax, the pound sign. What can I do?

Ryan ;-]
 
Hehe, I always get in trouble assuming :) Try this,

<CFIF evaluate(&quot;Form.UpFile#x#&quot;) NEQ &quot;&quot;>

Anytime you want to access the value of a dynamic variable, you have to wrap it with evaluate.

Let me know if you still have trouble,
GJ
 
Is there any way to do client-side validation?

Ryan ;-]
 
I think Javascript will be your only option there. I'm not aware of any code that the major browsers use for limiting file input choices.

GJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top