7 Replies Latest reply on Jul 1, 2011 6:37 AM by eb_dev

    cffile upload -  how do you pass form.file through a function?

    eb_dev Level 1

      I'm having a real headache with trying to implement a function which will take a file from form and then upload it (or really copy it to a destination dir) using cffile.


      Here is my code:


      <cffunction name="Upload" access="remote" output="false" returntype="any">


          <cfargument name="file" required="true">


          <cffile action="upload" fileField="arguments.file" destination="#ExpandPath('.')#" nameConflict="makeunique">


          <cfreturn cffile>


      <cfif NOT isDefined("form.submitted")>


           <form action="index.cfm" method="post" enctype="multipart/form-data">
              <input type="hidden" name="submitted" id="submitted" />
              <input type="file" name="file" id="file" />
              <input type="submit" name="submit" value="Submit" />
              <cfif isDefined("form.file")>
                  <cfdump var="#form#">
                      response = Upload(Form.file);


                  <cfdump var="#response#">
                  <cfoutput>No file</cfoutput>


      The error message I'm getting is:


      The form field arguments.file did not contain a file.


      What I don't understand is, why does it work when I pass the form.file to the fileField of cffile upload and not when I simply pass it through a function? Is there some sort of hidden security here or something?


      I've tried all sorts of variations with this without success. If someone could tell me where I am going wrong I would greatly appreciate it!