|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
Hi All,
I have a multi-page form that asks the user how many image files they want to upload on the first page. The second page then loops to create a form with as many file upload fields as they need. The third page should process the files individually by looping over the form fieldnames; however, I'm having trouble with the syntax. I've been able to do this with non-file variables, but I'm stuck here. ******************************* Quotations around the EVALUATE function ...IsDefined("Evaluate(... returns the following error: ******************************* Error Occurred While Processing Request Invalid CFML construct found on line 25 at column 28. ColdFusion was looking at the following text: ImageFile The CFML compiler was processing: an expression beginning with "IsDefined", on line 25, column 7.This message is usually caused by a problem in the expressions structure. a cfif tag beginning on line 25, column 2. a cfif tag beginning on line 25, column 2. ******************************* No quotations returns the temp variable for the file and also creates an error: ******************************* Error Occurred While Processing Request Parameter 1 of function IsDefined, which is now "C:\CFusionMX\runtime\servers\default\SERVER-INF\temp\wwwroot-tmp\neotmp48611.tmp", must be a syntactically valid variable name. The Error Occurred in C:\CFusionMX\wwwroot\ihs\submissions\imageaction.cfm: line 25 23 : <!--- Begin looping through the image files and process them for upload ---> 24 : <cfloop from="1" to="#FORM.NumRecords#" index="ThisRow"> 25 : <cfif IsDefined(Evaluate("ImageFile" & ThisRow)) Thanks! Matt <!--- Begin looping through the image files and process them for upload ---> <cfloop from="1" to="#FORM.NumRecords#" index="ThisRow"> <cfif IsDefined(Evaluate("ImageFile" & ThisRow)) AND Evaluate("ImageFile" & ThisRow) IS NOT ""> <cflock scope="session" timeout="50" throwontimeout="yes" type="exclusive"> <cftry> <cffile action="upload" filefield="#Evaluate("ImageFile" & ThisRow)#" destination="C:\websites\uecijv\imageprocess\" nameconflict="makeunique"> <cfif CFFILE.FileSize GT 200000> <cfthrow type="SizeError" message="Your image file exceeds the limit. It may not be larger than 200K"> </cfif> <cfif CFFILE.ClientFileExt NEQ "gif" AND CFFILE.ClientFileExt NEQ "jpg"> <cfthrow type="ExtError" message="Your image file is not the correct type. You may only upload GIF or JPG files"> </cfif> <cfcatch type="SizeError"> <cflocation url="sizeerror.cfm"> </cfcatch> <cfcatch type="ExtError"> <cflocation url="typeerror.cfm"> </cfcatch> </cftry> <cfif CFFILE.ServerFileExt EQ "jpg"> <CFX_IMAGE Action="RESIZE" FILE="C:\websites\uecijv\imageprocess\#CFFILE.ServerFile#" OUTPUT="C:\websites\uecijv\images\properties\large\#CFFILE.ServerFile#" WIDTH="480" QUALITY="75" > <CFX_IMAGE Action="RESIZE" FILE="C:\websites\uecijv\imageprocess\#CFFILE.ServerFile#" OUTPUT="C:\websites\uecijv\images\properties\small\#CFFILE.ServerFile#" WIDTH="160" HEIGHT="120" QUALITY="75" > <cfelse> <CFX_IMAGE Action="RESIZE" FILE="C:\websites\uecijv\imageprocess\#CFFILE.ServerFile#" OUTPUT="C:\websites\uecijv\images\properties\large\#CFFILE.ServerFile#" WIDTH="480" > <CFX_IMAGE Action="RESIZE" FILE="C:\websites\uecijv\imageprocess\#CFFILE.ServerFile#" OUTPUT="C:\websites\uecijv\images\properties\small\#CFFILE.ServerFile#" WIDTH="160" HEIGHT="120" > </cfif> </cflock> <cfquery datasource="#IHSDSN#" username="#IHSAppUser#" password="#IHSAppPass#"> UPDATE images SET Caption='#Evaluate("Caption" & ThisRow)#', ImageFile='#CFFILE.ServerFile#' WHERE image_id='#Evaluate("update" & ThisRow)#' </cfquery> <!--- If they left the field blank, delete the placeholder ---> <cfelseif NOT IsDefined(Evaluate("ImageFile" & ThisRow)) OR Evaluate("ImageFile" & ThisRow) IS ""> <cfquery name="qremoveentry" datasource="#IHSDSN#" username="#IHSAppUser#" password="#IHSAppPass#"> DELETE FROM images WHERE image_id='#Evaluate("update" & ThisRow)#' </cfquery> </cfif> </cfloop> |
|
#2
|
|||
|
|||
|
If you are sending the form fields to CF with names like "ImageFile1", "ImageFile2", etc., then I don't think you need to use evaluate(). You should just be able to do:
<cfif isDefined( 'ImageFile#thisRow#' ) >... you could also do: <cfif structKeyExists( 'form', 'ImageFile#thisRow#' )>...
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
For both of those alternatives, the following error is returned:
Error Occurred While Processing Request Invalid CFML construct found on line 25 at column 68. ColdFusion was looking at the following text: # The CFML compiler was processing: a cfif tag beginning on line 25, column 2. a cfif tag beginning on line 25, column 2. The Error Occurred in C:\CFusionMX\wwwroot\ihs\submissions\imageaction.cfm: line 25 23 : <!--- Begin looping through the image files and process them for upload ---> 24 : <cfloop from="1" to="#FORM.NumRecords#" index="ThisRow"> 25 : <cfif structKeyExists( 'FORM', 'ImageFile#ThisRow#' ) AND ImageFile#ThisRow# IS NOT ""> 26 : <cflock scope="session" timeout="50" throwontimeout="yes" type="exclusive"> 27 : <cftry> |
|
#4
|
|||
|
|||
|
I shouldn't have put quotes around the 'form' scope in the structKeyExists() call, but the isDefined() one should work. Here are working examples of both approaches:
Code:
<cfscript> form.image1 = "Image One"; form.image2 = "Image Two"; form.totalImages = 2; </cfscript> <cfoutput> <cfloop index="thisImage" from="1" to="#form.totalImages#"> <cfif structKeyExists( form, 'image#thisImage#' )> Image#thisImage# exists as a key in the Form struct.<br> </cfif> <cfif isDefined( 'form.image#thisImage#' )> form.image#thisImage# is defined too.<br> </cfif> <br> </cfloop> </cfoutput> |
|
#5
|
|||
|
|||
|
Thanks! That worked. I was able to use the StructFind function to check for NULL values:
StructFind(FORM, 'ImageFile#ThisRow#') IS NOT "" |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Looping Over CFFILE Uploads |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|