CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   ColdFusion (http://www.codingforums.com/forumdisplay.php?f=45)
-   -   Multiple File Upload Help (http://www.codingforums.com/showthread.php?t=160220)

Rick7707 03-03-2009 02:42 PM

Multiple File Upload Help
 
I keep getting this error: Element NUMBEROFFIELDS is undefined in VARIABLES

If anyone could help I would appreciate it.

Here is the client side:
<cfset numberoffields = 4>
<form action="fileupload.cfm" method="post" enctype="multipart/form-data">
<cfloop index="i" from="1" to="#numberoffields#" step="1">
<cfset filename = "file" & #i#>

<input type="file" name="<cfoutput>#filename#</cfoutput>" /><br />

</cfloop>

<input type="submit" name="submit" value="Upload">
</form>

Here is the server side:
<cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
<cfset filename = "form.file" & #i#>

<cfif evaluate(variables.filename) NEQ "">

<cffile action="upload" filefield="#variables.filename#" destination="d:\bla\bla\bla" accept="image/jpg, image/png, image/x-png, application/msword, application/vnd.ms-word, application/mspowerpoint, application/vnd.ms-powerpoint, application/pdf, application/msexcel, application/vnd.ms-excel" nameconflict="makeunique">
</cfif>
</cfloop>

SunshineFreedom 03-20-2009 03:16 PM

Quote:

Originally Posted by Rick7707 (Post 788481)
I keep getting this error: Element NUMBEROFFIELDS is undefined in VARIABLES

Your numberoffields variable is not persistent. One option is to set it as a hidden form field, then on your server-side read it as form.numberoffields.

Code:

...
Client side:
<form action="fileupload.cfm" method="post" enctype="multipart/form-data">
<input type="hidden" name="numberoffields" value="4">

        <cfloop index="i" from="1" to="#numberoffields#" step="1">
    <cfset filename = "file" & #i#>...

Server side:

Code:

<cfloop index="i" from="1" to="#form.numberoffields#" step="1">


All times are GMT +1. The time now is 02:19 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.