Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Get the file size

Hi,

I need help.

I need to assign the list to the variable.


//I upload the file first
 <cfloop from="1" to="#variables.maxFiles#" index="ii">
     
      <cftry>
            <cfif StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))>
             <CFFILE ACTION="UPLOAD"
                        FILEFIELD="AttachFile#ii#"
                        DESTINATION="#variables.filelocation#"
                        NAMECONFLICT="makeunique">
     
             <cfset Attachments=ListAppend(variables.Attachments,cffile.serverfile)>
             
//here I get the size of the file in the list
             <cfset GetFileSize=ListAppend(variables.GetFileSize,cffile.filesize)>

            </cfif>

//here I want to assign them into variable so I can insert the value into the database

			<cfloop list="#variables.GetFileSize#" index="fg" delimiters=","> 
				<cfset variables["filesize" & fg] = #fg#>
			</cfloop>

      </cfloop>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dgrafx
dgrafx
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure the benefit of moving the values into variables, why not just  upload and insert inside the loop?
like this..

 <cfloop from="1" to="#variables.maxFiles#" index="ii">
     
      <cftry>
            <cfif StructKeyExists(form,"AttachFile" & ii) && len(trim(Form["AttachFile" & ii]))>
             <CFFILE ACTION="UPLOAD"
                        FILEFIELD="AttachFile#ii#"
                        DESTINATION="#variables.filelocation#"
                        NAMECONFLICT="makeunique">
     
			 <cfquery name="insertFile" datasource="#request.datasource#">
		         insert into myFiles (serverName, fileSize, ...)
				 values ('#cffile.serverfile#', #val(cffile.filesize)#
		     </cfquery>

            </cfif>
        <cfcatch type="Any">
		    Failed to upload file
		</cfcatch>
	</cftry>
</cfloop>	 

Open in new window

the main drawback is that you are connecting / disconnecting to the DB on each iteration of the loop.
even if in this case it may be that there is not enough traffic to cause a load problem - still ...
I think it's misleading to say you're "connecting" to the database each time as the database connection stays open, but, yes you are accessing the database multiple times.  However, based on the time length of a typical cfquery statement, you could conceivably run 50 cfquery statements on a page all within a fraction of a second.   I would not be concerned with 3-5 insert statements.
Avatar of lulu50

ASKER

Thank you!!!

It works!!!

just what I am looking for.

Thank you again.
glad i could help ...