Solved

Get the file size

Posted on 2014-07-25
6
134 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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