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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple CFFILE uploads

Status
Not open for further replies.

swilensky

Programmer
Mar 14, 2001
6
US
I have a form that is uploading up to four files:

Picture 1:<input type=&quot;file&quot; name=&quot;pic1&quot; size=&quot;20&quot;>
Picture 2:<input type=&quot;file&quot; name=&quot;pic2&quot; size=&quot;20&quot;>
Picture 3:<input type=&quot;file&quot; name=&quot;pic3&quot; size=&quot;20&quot;>
Picture 4:<input type=&quot;file&quot; name=&quot;pic4&quot; size=&quot;20&quot;>

and a second page that is doing the uploads:

<cfif Trim(pic1) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic1&quot; nameconflict=&quot;makeunique&quot;>
</cfif>
<cfif Trim(pic2) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic2&quot; nameconflict=&quot;MAKEUNIQUE&quot;>
</cfif>
<cfif Trim(pic3) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic3&quot; nameconflict=&quot;makeunique&quot;>
</cfif>
<cfif Trim(pic4) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic4&quot; nameconflict=&quot;makeunique&quot;>
</cfif>


The uploading works fine... the problem arises when I try to insert the names of the uploaded files into a database. I am using the #file.clientfile# value but this only captures the last uploaded file's information, not all of the files. Is there a way to get each files name to insert into the table at the time of upload?

Thanks!!
 
One solution is to prepare a set of variables to use in your one CFQUERY action.

<!--- ready your array --->
<CFSET fileArray = arrayNew(1)>

<!--- upload and prep variable 1 --->
<cfif Trim(pic1) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic1&quot; nameconflict=&quot;makeunique&quot;>
<CFSET fileArray[1] = lcase(file.clientfile)>
</cfif>
<!--- --->

<!--- upload and prep variable 2 --->
<cfif Trim(pic2) IS NOT &quot;&quot;>
<cffile action=&quot;upload&quot; destination=&quot;server's address&quot; filefield=&quot;pic2&quot; nameconflict=&quot;makeunique&quot;>
<CFSET fileArray[2] = lcase(file.clientfile)>
</cfif>
<!--- --->

Then loop through the length of this new array, and insert one record for each iteration.

<!--- loop 2 times (because only 2 pics were sent) --->
<CFLOOP from=&quot;1&quot; to=&quot;#arrayLen(fileArray)#&quot; index=&quot;incr&quot;>
<CFQUERY name=&quot;x&quot; datasource=&quot;#ds#&quot;>
insert into TABLE
(
FIELD
)
values
(
'#fileArray[incr]#'
)
</CFQUERY>
</CFLOOP>

This of course assumes that you always use the same convention of naming your inputs. (pic1, pic2, pic3)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top