4 Replies Latest reply on Jul 14, 2006 1:53 PM by Newsgroup_User

    File uploads in cfc without accessing form scope?

    Level 7
      How do I use cffile (upload) in a cfc without accessing the form scope
      directly?

      I thought I just needed to evaluate the argument variable but that isn't
      working.

      As expected, this works:
      <cffile action="upload" filefield="form.document"
      destination="#expandPath('../../temp/')#" nameconflict="overwrite" />

      But this doesn't:
      <cffile action="upload" filefield="#arguments.docObj.document#"
      destination="#expandPath('../../temp/')#" nameconflict="overwrite" />

      It returns the following error:
      The form field
      "C:\CFusionMX7\runtime\servers\coldfusion\SERVER-INF\temp\wwwroot-tmp\neotmp45734.tmp"
      did not contain a file.

      Any ideas?

      --
      Bryan Ashcraft (remove brain to reply)
      Web Application Developer
      Wright Medical Technologies, Inc.
      ------------------------------------------------------------------
      Macromedia Certified Dreamweaver Developer
      Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/



        • 1. File uploads in cfc without accessing form scope?
          Dan Bracuk Level 5
          Might have something to do with the way you are passing your arguments. Hard to say since you didn't include that. Or maybe it's your cfargument tag.
          • 2. Re: File uploads in cfc without accessing form scope?
            Level 7
            Sorry. I'm passing them in a struct.
            Like so:

            <cfset doc =
            createObject('component','_cfcs.document').modifyDocument(attributes) />


            --
            Bryan Ashcraft (remove brain to reply)
            Web Application Developer
            Wright Medical Technologies, Inc.
            ------------------------------------------------------------------
            Macromedia Certified Dreamweaver Developer
            Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


            "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
            news:e98h2b$1ou$1@forums.macromedia.com...
            > Might have something to do with the way you are passing your arguments.
            > Hard to say since you didn't include that.


            • 3. Re: File uploads in cfc without accessing form scope?
              Level 7
              I had the same trouble. Someone posted some useful code. Here is what I have

              <cffunction name="uploadFile"
              access="public"
              returntype="string"
              hint="upload a file; return the file's extension or the
              error message"
              output="false">
              <cfargument name="source_str"
              type="string"
              required="true"
              hint="file (name & extension) of the file to be
              uploaded (client)">
              <cfargument name="destination_str"
              type="string"
              required="true"
              hint="path & filename of the uploaded file
              (server)">
              <cfargument name="accept_str"
              type="string"
              required="true"
              hint="list of acceptable MIME types or file types
              e.g. text/plain, application/msword, application/pdf,
              application/vnd.ms-excel, application/rtf, application/zip, image/gif,
              image/jpeg, image/png, text/html, text/rtf, text/xml">

              followed by

              <cffile action="upload"
              filefield="#arguments.source_str#"
              destination="#destination_str#"
              accept="#accept_str#">

              This is the only place that I use arguments. For some reason it seems to
              keep the "hidden" form attributes. If you find something better, please
              post.

              hth

              -brian


              • 4. Re: File uploads in cfc without accessing form scope?
                Level 7
                I'm not following what is going on. How are the form fields passed and is
                source)str the file field in the form? What do you mean about hidden form
                attributes? Are you using JS to save the file field's value to a hidden form
                element?

                My brain is fried at the moment, so forgive me if I'm missing something
                obvious.

                --
                Bryan Ashcraft (remove brain to reply)
                Web Application Developer
                Wright Medical Technologies, Inc.
                ------------------------------------------------------------------
                Macromedia Certified Dreamweaver Developer
                Adobe Community Expert (DW) :: http://www.adobe.com/communities/experts/


                "Brian Hogue" <bhogue@npcc.org> wrote in message
                news:e98kfg$660$1@forums.macromedia.com...
                >I had the same trouble. Someone posted some useful code. Here is what I
                >have
                >
                > <cffunction name="uploadFile"
                > access="public"
                > returntype="string"
                > hint="upload a file; return the file's extension or the
                > error message"
                > output="false">
                > <cfargument name="source_str"
                > type="string"
                > required="true"
                > hint="file (name & extension) of the file to be
                > uploaded (client)">
                > <cfargument name="destination_str"
                > type="string"
                > required="true"
                > hint="path & filename of the uploaded file
                > (server)">
                > <cfargument name="accept_str"
                > type="string"
                > required="true"
                > hint="list of acceptable MIME types or file types
                > e.g. text/plain, application/msword, application/pdf,
                > application/vnd.ms-excel, application/rtf, application/zip, image/gif,
                > image/jpeg, image/png, text/html, text/rtf, text/xml">
                >
                > followed by
                >
                > <cffile action="upload"
                > filefield="#arguments.source_str#"
                > destination="#destination_str#"
                > accept="#accept_str#">
                >
                > This is the only place that I use arguments. For some reason it seems to
                > keep the "hidden" form attributes. If you find something better, please
                > post.
                >
                > hth
                >
                > -brian
                >