Coldfusion FileUpload function from cfc file not working -
i trying upload file using function cfc file. can code work when call <cffile action="upload">
on same page. however, wanted learn how call function in cfc file. believe there problem arguments i'm passing attributes of <cffile>
tag, i'm not sure.
here html form:
<form action="confirm.cfm" method="post" enctype="multipart/form-data"> first name: <input type="text" name="fname" size="25" /> <br /> last name: <input type="text" name="lname" size="30" /> <br /> upload attachment file here: <input type="file" name="fileupload" id="fileupload" size="30" onchange="passfilename()" /> <br /> <input type="hidden" name="filename" id="filename" /> <br /> <input type="submit" value="submit" /> <input type="reset" name="reset form" /> <div id="filenamesection"> </div> </form>
here code form submitting confirm.cfm page
<cfif isdefined("form.fileupload")> <cfinvoke component="fileuploadexample" method="uploadfile" filetoupload="#form.fileupload#" sizemax="50" returnvariable="filenamereturn"> <cfelse> <cflocation url="index.cfm"> </cfif> <h1> thank filling out form </h1> <cfoutput> <table> <h3> please review , confirm information below </h3> <tr> <td> first name entered </td> <td> #form.fname# </td> </tr> <tr> <td> last name entered </td> <td> #form.lname# </td> </tr> <tr> <td> name of file uploaded? </td> <td> #form.filename# </td> </tr> </table> </cfoutput> file <cfoutput> #form.filename# </cfoutput> has been uploaded
here code fileuploadexample.cfc file
<cfcomponent> <cffunction name="uploadfile" access="public" output="no" returntype="string"> <cfargument name="filetoupload" type="string" required="no"> <cfset var cffile=""> <cffile action="upload" destination="c:\filepath\example\whatevafolder\" filefield="#arguments.filetoupload#" nameconflict="overwrite"> <cfreturn cffile.clientfile> </cffunction> </cfcomponent>
the error keep receiving when upload file is:
neotmp84939430443.tmp did not contain file.
when using upload cffile, needs form field name - passing in form field value. please see this link exact method achieve trying do.
Comments
Post a Comment