Adding to Array problem
Hi All,
I have a form which the user can upload a document to a location on my server. Basically everytime the user uploads a document I would like to add the information into an array so I can store the information in memory and then when the user clicks on the save button I will save away the information in the array. I am having a slight issue when inserting a row into the array, it seems to work on the intial first time but when the user tries to upload a second document only the current information shows in the last row of the array and wiping out anything before that.
Any help would be much apprciated I have attached my code in the hope someone can.
Many thanks,
George
<cfparam name="form.document" type="string" default="" />
<cfparam name="form.submitted" type="string" default="0" />
<cfparam name="form.ArLen" type="string" default="0">
<cfset REQUEST.Errors = ArrayNew(1) />
<!--- Create 2D array --->
<cfif isdefined("DocumentsArray") or (form.submitted neq 0)>
<cfset DocumentsArray = ArrayNew(2)>
</cfif>
<cfset tDate = "#dateformat(now(), "yyyymmdd")#">
<cfset tTime = "#timeformat(now(), "HHmmss")#">
<cfif Val(FORM.submitted)>
<cfif NOT Len(FORM.document)>
<cfset ArrayAppend(REQUEST.Errors,"Please select a file to upload.") />
</cfif>
<cfif NOT ArrayLen(REQUEST.Errors)>
<!--- Upload document --->
<cffile action="UPLOAD" destination="#ExpandPath('#get_serversettings.root_data_path#')#" filefield="document" nameconflict="MAKEUNIQUE"/>
<cfset tFileLoc = #get_serversettings.root_data_path# & #tFileName# & "." & #CFFILE.clientFileExt#>
<cfset tSourceLoc = #get_serversettings.root_data_path# & #CFFILE.ServerFile#>
<!--- **************************** --->
<!--- STEP 1: Build array contents --->
<!--- **************************** --->
<cfif isdefined("form.ArLen")>
<cfset form.ArLen = #form.ArLen# + 1>
</cfif>
<cfset DocumentsArray[#form.ArLen#][1] = #UAC#>
<cfset DocumentsArray[#form.ArLen#][2] = #AppealRef#>
<cfset DocumentsArray[#form.ArLen#][3] = now()>
<cfset DocumentsArray[#form.ArLen#][4] = #CFFILE.ServerFile#>
<cfset DocumentsArray[#form.ArLen#][5] = #tFileName#>
</cfif>
</cfif>
<cfoutput>
<fieldset>
<legend>Upload Document</legend>
<cfif ArrayLen(REQUEST.Errors)>
<ul>
<cfloop index="intError" from="1" to="#ArrayLen(REQUEST.Errors)#" step="1">
<li>#REQUEST.Errors[intError]#</li>
</cfloop>
</ul>
<cfelse>
<ul>
<cfif Val(FORM.submitted)>
<li>File uploaded.</li>
</cfif>
</ul>
</cfif>
<form action="#CGI.script_name#" method="post" enctype="multipart/form-data">
<input type="hidden" name="submitted" value="1"/>
<input type="hidden" name="ArLen" value="#form.ArLen#">
<label>Select a file:</label>
<input type="file" name="document" value="" size="50" /><br /><br />
<input type="submit" value="Upload" />
</form>
</fieldset>
</cfoutput>
<cfoutput>
<cftry>
<cfdump var=#DocumentsArray#>
<cfcatch></cfcatch>
</cftry>
</cfoutput>
