How Can I write this as a loop?
Here is some code I have to upload photos. Right now, I want people to be able to upload 20 photos. This works, but I want to reduce the code and be able to define how many photos via variable. In the code below, the number of each photo is included in the variable. If I create a loop, I can't use the #index# where some of these variables are defined, because it puts a variable within a variable.
Here is a chunk of the code for 'photo 2'. The code would be the same for 1-20, but the number would be different. I want the number to be the INDEX value in the loop.
Below the code, I have how I would like it to loop. How could I make this work? I've been digging around but haven't figured it out yet.
<!--- Photo 2 --->
<CFIF (isDefined("FORM.photo_file_2") AND FORM.photo_file_2 NEQ "")>
<CFSET local_photo_position = '2'>
<CFSET local_photo_caption = '#FORM.photo_caption_2#'>
<CFFILE
action="upload"
destination="c:\imagehost\classifieds\#main_category#\#CID#"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_2"
>
<CFINCLUDE TEMPLATE="#new_photo#">
</CFIF>
<!--- --->
<!--- LOOP STRUCTURE --->
<CFLOOP index="index" from="1" to "#userDefined#">
<CFIF (isDefined("FORM.photo_file#INDEX#") AND FORM.photo_file_#index# NEQ "")>
<CFSET local_photo_position = '#INDEX#'>
<CFSET local_photo_caption = '#FORM.photo_caption_(#INDEX#)#'> <!--- PROBLEM --->
<CFFILE
action="upload"
destination="c:\imagehost\classifieds\#main_category#\#CID#"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_#INDEX#"
>
<CFINCLUDE TEMPLATE="#new_photo#">
</CFIF>
</CFLOOP>
Here is some code I have to upload photos. Right now, I want people to be able to upload 20 photos. This works, but I want to reduce the code and be able to define how many photos via variable. In the code below, the number of each photo is included in the variable. If I create a loop, I can't use the #index# where some of these variables are defined, because it puts a variable within a variable.
Here is a chunk of the code for 'photo 2'. The code would be the same for 1-20, but the number would be different. I want the number to be the INDEX value in the loop.
Below the code, I have how I would like it to loop. How could I make this work? I've been digging around but haven't figured it out yet.
<!--- Photo 2 --->
<CFIF (isDefined("FORM.photo_file_2") AND FORM.photo_file_2 NEQ "")>
<CFSET local_photo_position = '2'>
<CFSET local_photo_caption = '#FORM.photo_caption_2#'>
<CFFILE
action="upload"
destination="c:\imagehost\classifieds\#main_category#\#CID#"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_2"
>
<CFINCLUDE TEMPLATE="#new_photo#">
</CFIF>
<!--- --->
<!--- LOOP STRUCTURE --->
<CFLOOP index="index" from="1" to "#userDefined#">
<CFIF (isDefined("FORM.photo_file#INDEX#") AND FORM.photo_file_#index# NEQ "")>
<CFSET local_photo_position = '#INDEX#'>
<CFSET local_photo_caption = '#FORM.photo_caption_(#INDEX#)#'> <!--- PROBLEM --->
<CFFILE
action="upload"
destination="c:\imagehost\classifieds\#main_category#\#CID#"
accept="image/jpg, image/jpeg, image/pjpeg, image/gif"
nameconflict="makeunique"
filefield="FORM.photo_file_#INDEX#"
>
<CFINCLUDE TEMPLATE="#new_photo#">
</CFIF>
</CFLOOP>