Solved

Get the file size

Posted on 2014-07-25
6
132 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

19 Experts available now in Live!

Get 1:1 Help Now