Copy link to clipboard
Copied
Hi,
I am trying to add the names of my uploads, but it keeps replacing the first item rather than adding more to the array.
<cfif IsDefined ("FORM.docs")>
<cffile action="upload" nameconflict="overwrite" destination="#ExpandPath("../../uploads/news")#" filefield="FORM.uploadDocuments" />
<cfset SESSION.uploads = ArrayNew(1)>;
<cfset ArrayAppend(SESSION.uploads, #CFFILE.clientfile#)>
<cfdump var="#SESSION.uploads#">
</cfif>
Thanks,
Ross
Copy link to clipboard
Copied
Please try this
<cfapplication sessionmanagement="true" >
<cfif IsDefined ("FORM.docs")>
<cffile action="upload" nameconflict="overwrite" destination="#ExpandPath("../../uploads/news")#" filefield="FORM.uploadDocuments" />
<cfif NOT isdefined("SESSION.uploads")>
<cfset SESSION.uploads = ArrayNew(1)>
</cfif>
<cfset ArrayAppend(SESSION.uploads, #CFFILE.clientfile#)>
<cfdump var="#SESSION.uploads#">
</cfif>
Copy link to clipboard
Copied
You are not outputing the code where you loop over the form items. All we see here is a new array made, then one item added.
Copy link to clipboard
Copied
You can go one of 2 ways. Use Catchme_dileep's cfif, or else replace the line <cfset SESSION.uploads = ArrayNew(1)> with:
<cfparam name="SESSION.uploads" default="#ArrayNew(1)#">