Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get the file size

Posted on 2014-07-25
6
Medium Priority
?
139 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 2000 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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

885 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