Here is what I use:
I call the cfc like so
<cfset dir = "e:\websites\accommodations\images">
<cfscript> session.lodging_mgr= createObject("component","lodging_manager.components.inn_access");
newImage=session.lodging_mgr.uploadImage(dir,'form.newImage',request.inn.password, request.inn.CustomerID);
</cfscript>
Notice that the formfield is passed only as it's name not a variable.


below is the cfc


<CFFUNCTION name="uploadImage" access="public" returntype="struct" hint="Uploads an image to a directory on the server. Requires imagefile, fully qualified directory path, base name for image and CustomerID.">
<CFARGUMENT name="thepath" type="any" required="true"/>
<CFARGUMENT name="thefield" type="any" required="true"/>
<CFARGUMENT name="imageName" type="any" required="true"/>
<CFARGUMENT name="CustomerID" type="any" required="true"/> <!--- SET THE REQUIRED VARS --->
<CFSET var returninfo=structnew()> <CFSET var uploadinfo=structnew()>
<cfparam name="errorReport" default="">
<!--- upload the image --->
<CFTRY>
<CFLOCK timeout="10" throwontimeout="No" name="timer" type="EXCLUSIVE">
<CFFILE action="UPLOAD"
filefield="#arguments.thefield#"
destination="#arguments.thepath#"
nameconflict="OVERWRITE" accept="image/gif,image/jpg, image/jpeg, image/bmp" />
</CFLOCK> <CFCATCH type="Any">
<CFSET errorReport="#errorReport#, Upload Error">
</CFCATCH>
</CFTRY>
<!--- i do a bunch of conversions and moving here in my cfc that I left out for readability--->


<CFSET returninfo.uploadinfo=structnew()> <CFSET returninfo.uploadinfo=duplicate(cffile)>

<cfif errorReport is "">
<cfset image="http://www.accommodations-vermont.com/database/images/#arguments.CustomerID#_image.jpg";>
<CFQUERY name="updateInn" datasource="datasource">
UPDATE innKeepers
SET
Photo =<CFQUERYPARAM value="#image#" cfsqltype="CF_SQL_VARCHAR" maxlength="75">,
Thumbnail =<CFQUERYPARAM value="#thumbnail#" cfsqltype="CF_SQL_VARCHAR" maxlength="75">
WHERE
CustomerID = <CFQUERYPARAM value="#arguments.CustomerID#" cfsqltype="CF_SQL_INTEGER">
</CFQUERY>
<CFSET returninfo.imagemessage="File has been uploaded and a thumbnail has been created">
<cfelse>
<CFSET returninfo.imagemessage=errorReport>
</cfif>
<CFRETURN returninfo/>
</CFFUNCTION>


<cfif form.newImage is not "">
<cfset dir = "e:\websites\www.accommodations\\images">
<cfscript> uploadImage = createObject("component","lodging_manager.components.inn_access");
newImage=uploadImage.uploadImage('#dir#','form.newImage','#request.inn.password#', #request.inn.CustomerID#);
</cfscript>


       </cfif>

Peter J. Farrell wrote:

Dave Carabetta wrote:

On Tue, 20 Jul 2004 14:14:12 -0400, Peter J. Farrell
<[EMAIL PROTECTED]> wrote:


Why don't you just pass in the the form field that has the file?
form.This_File to arguments of the CFC?



Because you get an error saying that "this field does not contain a
file" (or something very similar). I tried that as in my first pass,
thinking along the same lines as you. That would be intuitive, right?
Well, apparently it has something to do with the way the file upload
works with cffile. Interestingly, if you were to do a cfdump of the
Arguments scope passing in only the file field, you'd see that the
value of the field is the tmp file that ColdFusion creates when it
uploads the file. Alas, an error is thrown when I try and call the
cffile tag using the passed-in Argument name. Hence, the need for the
form scope reference.

Does that make sense?

Regards,
Dave.
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]



I haven't worked too much with cffile, but if what you say that the passed reference is the name of the temp file CF creates when you upload it...couldn't you just read that file by using the reference and rename or move it?

.pjf
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev' in the message of the email.


CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to