Figured out my problem.. Was a SUP - stupid user problem.
<cffile
action="UPLOAD"
filefield="#arguments.formField#"
destination="#arguments.destination#"
nameconflict="#arguments.nameconflict#"
accept="#arguments.accept#"
attributes = "normal"
result = "result_name">
It was the last line [result = "result_name">] that caused the problem.
Notes in the books stated that cffile was the default but it was not til I
took the advice of one of my friends to do a <cfdump var="#variables#> that
an inkling of the shot in the foot had a occurred. Searching Livedocs
found:
{{{result - Optional - Allows you to specify a name for the variable in
which cffile returns the result (or status) parameters. If you do not
specify a value for this attribute, cffile uses the prefix 'cffile'. For
more information, see the Usage section.}}}
Thanks again for your response, and have a great day.
Dougc
"Nate Nielsen"
<[EMAIL PROTECTED]
om> To
Sent by: "Dallas/Fort Worth ColdFusion User
[EMAIL PROTECTED] Group Mailing List"
s1.safesecureweb. <[EMAIL PROTECTED]>
com cc
Subject
10/29/2006 10:14 Re: [DFW CFUG] Problem with a CFC
PM for uploading a file
Please respond to
"Dallas/Fort
Worth ColdFusion
User Group
Mailing List"
<[EMAIL PROTECTED]
secureweb.com>
I just skimmed over it, so this may not be it, but something to check out.
i.e. you change the call like this (removed "form."):
<cfinvokeargument name="formField" value="aFile">
don't think CF expects that form prefix, it expects a string of the field
name.
again, not sure that is your issue, but jumped out at me.
-Nate Nielsen
[EMAIL PROTECTED]
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, October 29, 2006 4:55 PM
Subject: [DFW CFUG] Problem with a CFC for uploading a file
>
> Ladies and Gentlemen,
>
> I hope someone can possibly provide some direction or help on this.
>
> Trying to create a simple file upload with a CFC doing the processing.
>
> Simple business rules.
>
> 1) Restrict the file type to Word
>
> 2) Upload one file (not multiples)
>
> 3) Assume the user will have Word files named with unacceptable special
> characters .. spaces, #, ! etc.
>
> 4) Ultimately plan to capture additional information along with the
> renamed
> filename into an SQL Server database to present the user an option to
> click
> n view on a page. (that is after I get past this.)
>
> I had created a simple couple .cfm's that worked, but wanted to move it
to
> a .CFC and invoke it from the action page. I thought it would be a
simple
> process, however, that has not been the case.
>
> My attempts failed. So I started doing some Googling.
>
> In the process I stumbled on a snippet of code associated with Farcry.
> It
> appeared to do alot of what I would like to achieve, but as this was my
> first foray into a serious CFC I wanted to follow a piece of working code
> to step through and follow.
>
> My attempt succeeds in uploading the file, but ERRORs at the point where
I
> attempt to identify the filename (using makeunique) to ensure it is
> unique.
>
> I have searched the web, and nothing seems to address this issue.
>
> I have checked all the CF books I have and have not had any success.
>
> As noted above the app fails after successfully uploading and saving the
> file to the destination folder.
>
> The error "Element SERVERFILE is undefined in CFFILE." implies to me that
> it recognizes the CFFILE object but not the SERVERFILE. I have tried
> lowercase, uppercase, camel case. I have tried both FILE vs CFFILE upper
> and lower case. Same result.
>
> My swag on this is it almost seems like the serverfile is referencing the
> .tmp file that has been moved to the DESTINATION folder and the undefined
> is a result of nothing there. Or that I am using incorrect but verified
> the FILE Attributes in CF MX & Web Application Construction Kit, pg 1024
> and again on the Adobe site.
>
> It appears from the research that the file is really uploaded to
> ...\wwwroot-tmp\neoxxxxx.tmp directory
>
> I am testing this on a WinXP Pro running PWS and developers edition of
> Coldfusion MX7
>
> CF version 7.0.0.91690
>
>
> My folder structure is:
> /fload
> /fload/docs
>
>
> My two CFM and the CFC files are as follows.
>
> I really suspect it is a SUP problem.. Stupid User Problem.
>
> Any suggestions or ideas would be greatly appreciated.
>
> Thanks in advance
>
> DougC
>
>
>
> <<<<<frmupload.cfm>>>>>
> ======================
> <html>
> <head>
> <title>Untitled Document</title>
> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
> </head>
>
> <body>
> <form action="upload_act.cfm" method="post"
enctype="multipart/form-data">
> File: <input type="file" name="aFile"><br>
> <input type="submit" value="Upload a File">
> </form>
> </body>
> </html>
>
>
> <<<<<upload_act.cfm>>>>>
> ======================
> <cfdump var="#form#">
> <cfdump var="#form.afile#">
>
> <cfinvoke
> component="uploadfileNew"
> method="uploadFile"
> returnvariable="uploadFooRet">
> <cfinvokeargument name="formField" value="form.aFile">
> <cfinvokeargument name="destination"
> value="c:\inetpub\wwwroot\fload\docs\">
> <cfinvokeargument name="nameconflict" value="makeunique">
> <cfinvokeargument name="accept" value="application/msword">
> </cfinvoke>
>
>
> <<<<uploadfileNew.cfc>>>>>
> ======================
> <cfcomponent displayName="Upload File">
> <!--- Function to address uploading a file, and then renaming the file to
> strip spaces and other
> special characters out of the filename
Found on --->
>
> <cffunction name="uploadFile" hint="Uploads a file">
> <cfargument name="formField" hint="The name of the field that
> contains the file to be uploaded" required="true" type="string">
> <cfargument name="destination" hint="Directory file is to be
> uploaded to - must pass in absolute path" type="string" default="">
> <cfargument name="nameconflict" hint="File write behavior"
> type="string" default="">
> <cfargument name="accept" hint="File types to accept"
> type="string" default="">
>
> <cfset var stReturn = structNew()>
> <cfset var validName = ''>
> <cfset var i = 1>
> <cfset stReturn.bSuccess = false>
>
> <cfif len(arguments.formField)>
> <cftry>
> <cfif NOT directoryExists(arguments.destination)>
> <cfdirectory action="create"
> directory="#arguments.destination#">
> </cfif>
>
> <cffile
> action="UPLOAD"
> filefield="#arguments.formField#"
> destination="#arguments.destination#"
> nameconflict="#arguments.nameconflict#"
> accept="#arguments.accept#"
> attributes = "normal"
> result = "result_name">
> <!--- Fails from this point on.. File uploads but get following error:
>
Exceptions
>
> 15:58:48.048 - Expression Exception - in
>
C:\Inetpub\wwwroot\fload\uploadfileNew.cfc : line 36
> Element
SERVERFILE is undefined in CFFILE. This is the
> following <cfif
statement
> --->
> <cfif
> refindnocase("[\$\^\s\%\*''""<>,\&?]",cffile.serverfile) gt 0>
> <cfset validName =
> rereplace(cffile.serverfile,"[?\$\^\s\%\*''""<>,\&]","_","ALL")>
>
> <cfset i = 1>
> <cfloop
> condition="#fileexists('#cffile.ServerDirectory#/#validName#')#">
> <cfset validName =
> rereplace(cffile.clientfilename,"[?\$\^\s\%\*''""<>,\&]","_","ALL") &
> "#i#." & listlast(cffile.serverfile,".")>
> <cfset i = i + 1>
> </cfloop>
>
> <cffile
> action="rename"
>
> source="#cffile.ServerDirectory#/#cffile.serverfile#"
>
> destination="#cffile.ServerDirectory#/#validName#">
> <cfelse>
> <cfset validName = cffile.serverfile>
> </cfif>
>
> <cfscript>
> stReturn.bSuccess = true;
> stReturn.message = "File upload Successful";
> stReturn.filename = validName;
> stReturn.fileDirectory =
> cffile.ServerDirectory;
> stReturn.fileSize = cffile.fileSize;
> stReturn.contentType = cffile.ContentType;
> stReturn.clientFileName =
> cffile.clientFileName;
> stReturn.contentSubType =
> cffile.contentSubType;
> stReturn.serverFile = validName;
> stReturn.serverDirectory =
> cffile.ServerDirectory;
> </cfscript>
>
> <cfcatch>
> <cfset stReturn.message = cfcatch.message>
> </cfcatch>
> </cftry>
> <cfelse>
> <cfset stReturn.message = "No file uploaded.">
> </cfif>
> <cfreturn stReturn>
> </cffunction>
>
> </cfcomponent>
>
>
> _______________________________________________
> Reply to DFWCFUG:
> [email protected]
> Subscribe/Unsubscribe:
> http://lists1.safesecureweb.com/mailman/listinfo/list
> List Archives:
> http://www.mail-archive.com/list%40list.dfwcfug.org/
> http://www.mail-archive.com/list%40dfwcfug.org/
> DFWCFUG Sponsors:
> www.HostMySite.com
> www.teksystems.com/
_______________________________________________
Reply to DFWCFUG:
[email protected]
Subscribe/Unsubscribe:
http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
http://www.mail-archive.com/list%40list.dfwcfug.org/
http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
www.HostMySite.com
www.teksystems.com/
_______________________________________________
Reply to DFWCFUG:
[email protected]
Subscribe/Unsubscribe:
http://lists1.safesecureweb.com/mailman/listinfo/list
List Archives:
http://www.mail-archive.com/list%40list.dfwcfug.org/
http://www.mail-archive.com/list%40dfwcfug.org/
DFWCFUG Sponsors:
www.HostMySite.com
www.teksystems.com/