Skip to main content
Inspiring
January 27, 2009
Question

A help in upload

  • January 27, 2009
  • 1 reply
  • 303 views
Hi i am trying to upload 5 files in row using a loop. but it showing me an erro:

here is the code i am tryinh:


<cfloop from="1" to="5" index="idx">
<cfoutput>
<cfif form.upload#idx# IS NOT "">
<cffile action="upload" filefield="upload#idx#" destination="#request.siteURL#core/#NewUploadDir#/"
nameconflict="makeunique" accept="image/*">
<cfset resizeFile = "#cffile.ServerFile#">
<cfset imageCFC = createObject("component","core.cfc.image") />
<cfset imageCFC.resize(','#request.file_path#core\#NewUploadDir#\#resizefile#','#request.file_path#core\#NewUploadDir#\rr_#resizefile#',150,150) />
<cfif fileexists('#request.file_path#core\#NewUploadDir#\#resizefile#')>
<cffile action="delete" file="#request.file_path#core\#NewUploadDir#\#resizefile#">
</cfif>
<cfset form.file#idx# = "rr_#resizefile#">
<cfelse>
<cfset form.file#idx# = "">
</cfif>
</cfoutput>
</cfloop>


it is showing me this error:

Invalid CFML construct found on line 12 at column 28.
ColdFusion was looking at the following text:

#

The CFML compiler was processing:
A cfif tag beginning on line 12, column 12.
A cfif tag beginning on line 12, column 12.
A cfif tag beginning on line 12, column 12.
A cfif tag beginning on line 12, column 12.

The error occurred in C:\Inetpub\wwwroot\project1\upload.cfm: line 12
10 : <cfloop from="1" to="5" index="idx">
11 : <cfoutput>
12 : <cfif form.upload#idx# IS NOT "">
13 : <cffile action="upload" filefield="upload#idx#" destination="#request.siteURL#core/#NewUploadDir#/"
14 : nameconflict="makeunique" accept="image/*">
This topic has been closed for replies.

1 reply

Inspiring
January 27, 2009
nightwolf666 wrote:
> <cfif form.upload#idx# IS NOT "">

This is not the correct way to dynamically access a form field name.
The best practice is to use array notation. I.E. <cfif form["upload" &
idx] IS NOT "">