EasyCFM.COM ColdFusion Forums / ColdFusion Applications / MULTIPLE UPLOAD

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: MULTIPLE UPLOAD

book mark this topic Printer-friendly Version  send this discussion to a friend  new posts last

GiuliaN
01-26-2007 @ 7:41 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Jan 2007

I am trying hardly to make a dynamic form in CF upload mustiple files using CFFILE. I have tried different codings, but none of them prooved to be successful. The form has a dynamic input which is specified in a previous page. I am posting the code, please give a hand thos who may have some better ideas. Thank you!

<cfif isDefined("form.imagesNumber")>
<cfset numba=form.imagesNumber>
<cfelse>
<cfset numba=1>
</cfif>
<cfoutput>#numba#</cfoutput>

<cfif not isDefined("form.submit")>
     <form action="somepage.cfm" method="post" enctype="multipart/form-data">
     <cfoutput>         
          <cfloop from="1" to="#numba#" index="i" step="1">
          File #i#:
          <input type="file" name="file#i#" id="file#i#"  /><br />
          </cfloop>
          </cfoutput>
          <input type="submit" value="PROCESS IMAGE" />
     </form>
<cfelse>
     <cfset myfilepath="#request.somepath#">
     <cfloop from="1" to="#numba#" index="i" step="1">
     <cfoutput>
     <cfif len(evaluate("form.file"&i)) GT 1>
     <cffile action="upload"
          filefield="form.file#i#"
           destination="#myfilepath#"
           nameconflict="MakeUnique">
     <cfset uploadedImage = "#cffile.serverfile#">
       </cfif>
       </cfoutput>     
     </cfloop>
</cfif>

mquack
01-26-2007 @ 4:33 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Try

<cffile action="upload"
          filefield="form['file' & i]"
           destination="#myfilepath#"
           nameconflict="MakeUnique">


http://www.rachelqueensg.com

This message was edited by mquack on 1-26-07 @ 4:34 PM

mquack
01-26-2007 @ 4:36 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Oh, and I just noticed your <cfif len()> statement.  Bad, bad, bad, bad.  Don't use evaluate().  Bad, bad, bad.  Use array notation instead, like I used above.

<cfif len(form['file' & i])>


http://www.rachelqueensg.com

GiuliaN
01-26-2007 @ 8:02 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Jan 2007

I tried the coding proposed by you..but..no result..it does not upload anything. I was thinking to quit using cfloop with cffile when uploading and instead to make a structure of the formdata and then
upload the formdata with cffile. Still..somewhere must be a problem! Can you please give me a hand?
The code is this:

    <cfloop from="1" to="#numba#" index="i">
      <cfset Session.FormData.files=form.file.>
      </cfloop>
      <cfset myfilepath="#request.actorsmen#">
     <cfoutput>
          <cffile action="upload"
          filefield="Session.FormData.files"
           destination="#myfilepath#"
           nameconflict="MakeUnique">
     <cfset uploadedImage = "#cffile.serverfile#">
      </cfoutput>      


This message was edited by GiuliaN on 1-26-07 @ 8:06 PM

mquack
01-26-2007 @ 9:00 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Moderator
Posts: 1544
Joined: Jan 2005

Okay, let's start over.  You say "it doesn't upload anything", but what DOES it do?

Does it throw an error?

Does it give you a blank screen?

Is this in a <cftry> block?

Is this in a CFC?

Is this in a regular .cfm?

Have you tried dumping the form structure to make sure that the fields you're expecting to exist actually do?

We need more to go on than "it doesn't work".  Smile


http://www.rachelqueensg.com

GiuliaN
01-27-2007 @ 6:49 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Jan 2007

I found what the problem was. Simply it must be written "file#i#" everywhere the code makes reference to the form file input fields in order to upload them using cffile. I will put all code here..for me its working perfectly and all the files get uploaded in the right directory. Thank you!

<cfset numba=3>
<cfparam name="form.step" default="1">
<cfif isDefined("url.step")>
<cfset form.step=2>
</cfif>

<cfswitch expression="#form.step#">

<cfcase value="1">

    <form method="post" enctype="multipart/form-data" name="form">
     <cfoutput>          
          <cfloop from="1" to="#numba#" index="i">
          File #i#:
          <input type="file" name="file#i#" id="file#i#"  /><br />
          </cfloop>
          </cfoutput>
            <input type="hidden" value="2" name="step" />
          <input type="submit" value="PROCESS IMAGE" onclick="InsertData();" />
     </form>
       </cfcase>
     
<cfcase value="2">
        <cfset myfilepath="#request.somepath#">
       <cfloop from="1" to="#numba#" index="i">
         <cfif evaluate("form.file#i#") NEQ "">         
         <cffile action="upload"
          filefield="form.file#i#"
           destination="#myfilepath#"
           nameconflict="MakeUnique">
     <cfset uploadedImage = "#cffile.serverfile#">
      </cfif>
      </cfloop>
       
            
</cfcase>
</cfswitch>    
    


GiuliaN
01-29-2007 @ 4:22 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
New Member
Posts: 4
Joined: Jan 2007

I do still have a problem though. When I give a
static value to "numba" like <cfset numba=3> the number of files to be uploaded, cffile is processing all the files entirely.If I assign to "numba" a dynamic value, defined by a form variable posted from a previous page, cffile is processing only 1 file?
Any ideas what I have to correct?
Thank you!


Website Designed and Developed by Pablo Varando.