Solved

Get the file size

Posted on 2014-07-25
6
133 Views
Last Modified: 2014-07-28
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

0
Comment
Question by:lulu50
  • 3
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
dgrafx earned 500 total points
ID: 40221513
Right after where you have your set attachments code
<cfset Attachments=ListAppend(variables.Attachments,cffile.serverfile)>
Add this:
<cfset variables["fileSize" & ii] = cffile.filesize>

Then to insert to DB for correct file you probably have something like this:
<cfset cnt=0>
<cfloop list="#variables.Attachments#" index="ii">
      <cfset cnt++/>
So then right here you have your file: #ii#
and here is the corresponding size: #variables["fileSize" & cnt]#

good luck ...
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 40221733
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

0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40221922
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 ...
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 39

Expert Comment

by:gdemaria
ID: 40222139
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.
0
 

Author Closing Comment

by:lulu50
ID: 40224008
Thank you!!!

It works!!!

just what I am looking for.

Thank you again.
0
 
LVL 25

Expert Comment

by:dgrafx
ID: 40224150
glad i could help ...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
A short film showing how OnPage and Connectwise integration works.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now