4 Replies Latest reply on May 10, 2007 9:20 AM by dame.cranon

    multiple cffile upload issues

    dame.cranon
      Hello all. I'm having a little issue with a multiple upload I am trying to achieve. I've been searching and searching but could not find an answer, and maybe you guys could help me. Well I'm doing multiple uploads on a form i created and it's uploading the file and file name correctly, but it's inserting 6 records everytime I'm hitting the submit button. Also, I've notice in my database is when you click the submit button, it's inserting the same file in one record 6 times, then it creates a new record and inserts the second file 6 times. I'm going to post the code here, maybe it's something I'm missing, not sure. Thanks for the help.

        • 1. Re: multiple cffile upload issues
          Level 7
          dame.cranon wrote:
          > Hello all. I'm having a little issue with a multiple upload I am trying to
          > achieve. I've been searching and searching but could not find an answer, and
          > maybe you guys could help me. Well I'm doing multiple uploads on a form i
          > created and it's uploading the file and file name correctly, but it's inserting
          > 6 records everytime I'm hitting the submit button. Also, I've notice in my
          > database is when you click the submit button, it's inserting the same file in
          > one record 6 times, then it creates a new record and inserts the second file 6
          > times. I'm going to post the code here, maybe it's something I'm missing, not
          > sure. Thanks for the help.
          >
          >
          >
          > <cfloop index="i" from="1" to="6">
          >
          > <cfif isDefined("form.upload")>
          >
          > <cffile action="upload"
          > destination="D:\Hosting\streetzmag\dev\crush_images\"
          > filefield="pic#i#"
          > nameconflict="makeunique"
          > result="cffile.pic#i#"
          > accept="image/jpeg, image/pjpeg, image/gif" >
          >
          > <!--- Code for insert of information --->
          > <cfquery datasource="mysqlcf_streetzmag" name="uploaded">
          > INSERT INTO Information(firstname,
          > lastname,
          > email,
          > contact_info,
          > nickname,
          > recent_work,
          > hair_color,
          > eye_color,
          > ethnicity,
          > age,
          > height,
          > measurements,
          > pic_1,
          > pic_2,
          > pic_3,
          > pic_4,
          > pic_5,
          > pic_6
          >
          >
          > )
          > VALUES('#FORM.firstname#',
          > '#FORM.lastname#',
          > '#FORM.email#',
          > '#FORM.contact#',
          > '#FORM.nickname#',
          > '#FORM.work#',
          > '#FORM.hair#',
          > '#FORM.eye#',
          > '#FORM.ethnic#',
          > #FORM.age#,
          > '#FORM.height#',
          > '#FORM.measurements#',
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>,
          >
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>,
          >
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>,
          >
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>,
          >
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>,
          >
          > <cfif isDefined("form.pic#i#") and evaluate("form.pic#i#") NEQ "">
          > <cfqueryparam value="#CFFILE['pic'&i].SERVERFILE#" cfsqltype="cf_sql_varchar"
          > />
          > <cfelse>
          > NULL
          > </cfif>
          >
          > )
          > </cfquery>
          > </cfif>
          > </cfloop>
          >

          of course it will do everything 6 times since you have your whole code
          wrapped with cfloop from 1 to 6... so the code execution will happen 6
          times... plus your synatx for inserting filenames inside your query
          makes it insert same file 6 times (since the code is inside one same
          cfloop)...

          you should separate your code and wrap only the cffile part in a cfloop:


          <cfif isDefined("form.upload")>

          <cfloop index="i" from="1" to="6">

          <cfif len(trim(form.pic#i#)) gt 0>
          <cffile action="upload"
          destination="D:\Hosting\streetzmag\dev\crush_images\"
          filefield="pic#i#"
          nameconflict="makeunique"
          result="uploadedpic_#i#"
          accept="image/jpeg, image/pjpeg, image/gif" >
          </cfif>

          </cfloop>

          <!--- Code for insert of information --->
          <cfquery datasource="mysqlcf_streetzmag" name="uploaded">
          INSERT INTO Information
          (firstname,
          lastname,
          email,
          contact_info,
          nickname,
          recent_work,
          hair_color,
          eye_color,
          ethnicity,
          age,
          height,
          measurements,
          pic_1,
          pic_2,
          pic_3,
          pic_4,
          pic_5,
          pic_6)
          VALUES('#FORM.firstname#',
          '#FORM.lastname#',
          '#FORM.email#',
          '#FORM.contact#',
          '#FORM.nickname#',
          '#FORM.work#',
          '#FORM.hair#',
          '#FORM.eye#',
          '#FORM.ethnic#',
          #FORM.age#,
          '#FORM.height#',
          '#FORM.measurements#',
          <cfloop from="1" to="6" index="x">
          <cfif isdefined("uploadedpic_#x#")>
          <cfqueryparam value="#evaluate('uploadedpic_' & x)#"
          cfsqltype="cf_sql_varchar"/>
          <cfelse>
          NULL
          </cfif>
          <cfif x lt 6>,</cfif>
          </cfloop>)
          </cfquery>

          </cfif>


          --

          Azadi Saryev
          Sabai-dee.com
          http://www.sabai-dee.com
          • 2. Re: multiple cffile upload issues
            dame.cranon Level 1
            Ok, I seperated the cfloop in my code now there is an error around line 71 somewhere. It's an invalid data error coming up now. Should I use the cffile in the cfqueryparam tag or not?
            • 3. Re: multiple cffile upload issues
              Level 7
              Did you change the cfquery code as Azadi did?
              Can you post the code, along with the error text?

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



              "dame.cranon" <webforumsuser@macromedia.com> wrote in message
              news:f1m5g0$q49$1@forums.macromedia.com...
              > Ok, I seperated the cfloop in my code now there is an error around line 71
              > somewhere. It's an invalid data error coming up now. Should I use the
              > cffile in the cfqueryparam tag or not?


              • 4. Re: multiple cffile upload issues
                dame.cranon Level 1
                Yes I figured it out. I was not including the <cfif> statement after the <cfparamquery> tag. Now it works like it's supposed to. Thanks for the help on this matter. It was counting the comma 6 times, instead of counting it 5 times, like stated in the <cfif> tag.