SunQuest
           ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old July 13th, 2004, 12:31 PM
stoneridge19 stoneridge19 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 stoneridge19 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 43 sec
Reputation Power: 0
Cool Looping Over CFFILE Uploads

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>

Reply With Quote
  #2  
Old July 13th, 2004, 12:43 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old July 13th, 2004, 01:04 PM
stoneridge19 stoneridge19 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 stoneridge19 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 43 sec
Reputation Power: 0
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>

Reply With Quote
  #4  
Old July 13th, 2004, 02:53 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,627 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 10 h 8 m 55 sec
Reputation Power: 53
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>

Reply With Quote
  #5  
Old July 14th, 2004, 01:38 PM
stoneridge19 stoneridge19 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 6 stoneridge19 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 43 sec
Reputation Power: 0
Smile

Thanks! That worked. I was able to use the StructFind function to check for NULL values:

StructFind(FORM, 'ImageFile#ThisRow#') IS NOT ""

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Looping Over CFFILE Uploads


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway