I am trying to create a functionality to allow a user to upload multiple files. 
My code (adopted from Charles Kaufmann) attempts this by making my form page 
submit chosen files to the same page for processing.

My attempts to achieve these have not succeeded. I either get an error telling 
me that the filename I have created is undefined (and I sort of understand 
that, because somewhere in my code I do check to see if the field is empty but 
I do not declare it previous to this - this is because I create it on the fly) 
or when I attempt to upload without checking for whether the field is empty, 
that "The form field XXX did not contain a file." while, I had chosen a file.

NB: The file information for which the files are being uploaded is passed to 
the form as a URL variable.

The code that I am using is (sorry it is long):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>eGhana -  Upload Extra Images</title>
</head>

<body>

<!--- Check that the user is authenticated, otherwise send them to the login 
page --->
<cfif not isDefined("SESSION.auth.isLoggedIn")>
    <cflocation url="consumerLogin.cfm">
   <!--- Create form for uploading extra images for product --->
</cfif>


<cfif IsDefined("URL.Cnsmr_ProductID")>
        <cflock timeout=20 scope="Session" type="Exclusive">
          <cfset Session.submitToSelf = 1>
    </cflock> 


 <!--- Assign the productID to a session variable --->
   
    <cflock timeout=20 scope="Session" type="Exclusive">
          <cfset Session.ExtraProductImgName = URL.Cnsmr_ProductID>
    </cflock>
</cfif>         
        

<!--- ????????????????????????????????????????????????????? --->
<!--- CHECK THE LOGIC - product name must be active for both upload field 
creation and actual upload process --->
   
   <!-- make sure that Cnsmr_ProductID has been passed -->
    
   <cfif not IsDefined("URL.Cnsmr_ProductID") and Session.submitToSelf eq 2 >
   <!--- if it wasn't, then return to the consumers ad list --->
   <cflocation url="consumerAd.cfm">
                  
         <cfelse> 
        
        <!---create session variable to hold number of form fields to create--->
        <cflock timeout=20 scope="Session" type="Exclusive">
          <cfset Session.numberoffields = 8>
    </cflock>
    
        
   <!--testing for the value of session variable -->
   <cfdump var="#Session.ExtraProductImgName#">
   
          <cfform action="uploadExtraConsumerProductImages.cfm" 
enctype="multipart/form-data" method="post">
        <cfloop index="i" from="1" to="#Session.numberoffields#" step="1"> 
          <cfset filename = "#Session.ExtraProductImgName#" & #i#>
                  <!--- Set the respective file name for the uploaded image --->
           <cfinput type="File" 
name="<cfoutput>#variables.filename#</cfoutput>" /><br />
                </cfloop>   
           <cfinput type="Submit" name="upload" value="upload" />
        </cfform>
   
   </cfif>

<cfif Session.submitToSelf eq 1 and isDefined("form.upload")>
 <!--- ????????????????????????????????????????????????????? --->


<!---create variable to hold destination of uploaded files--->
<cfset upLoadDestination = "#ExpandPath('images/consumer/')#">
    <cfif isdefined("form.upload")> 
      <cfloop index="i" from="1" to="#Session.numberoffields#" step="1">
           <cfset filename = "#Session.ExtraProductImgName#" & #i#>
             <!--- cfif evaluate(variables.filename) neq "" --->
                  <cffile action="UPLOAD" destination="#upLoadDestination#" 
nameconflict="makeunique" filefield="#variables.filename#">
                 <!---/cfif---> 
          </cfloop>
           
           <!--- Delete the session variable after uploading files related to 
this particular ProductID --->
           <cflock timeout=20 scope="Session" type="Exclusive">
             <cfset StructDelete(Session, "ExtraProductImgName")>
       </cflock>
           
    <!--- disable resubmit flag after resubmitting --->
        <cflock timeout=20 scope="Session" type="Exclusive">
          <cfset Session.submitToSelf = 2>
    </cflock>
    </cfif>
</cfif> <!--- end extra upload processing --->
           
</body>
</html>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;207172674;29440083;f

Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:321032
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to