It is possible, as mentioned above, I'm using it to determine the filesize of 1 field now.
Main Topics
Browse All TopicsCurrently, I have 1 file upload field, for which I'm using "CGI.CONTENT_LENGTH" to check the size of the file before uploading it to my server.
I'm thinking of allowing multiple uploads by using the tutorial from devarticles.com:
(Upload.cfm)
<cfset numberoffields = 10>
<form action="Upload_action.cfm"
<cfloop index="i" from="1" to="#variables.numberoffie
<cfset filename = "file" & #i#>
<input type="File" name="<cfoutput>#variables
</cfloop>
<input type="Submit" name="upload" value="upload" />
</form>
(/Upload.cfm)
(Upload_action.cfm)
<cfloop index="i" from="1" to="#variables.numberoffie
<cfset filename = "form.file" & #i#>
<cfif evaluate(variables.filenam
<cffile action="UPLOAD"
destination="c:cfusionmxww
nameconflict="OVERWRITE"
filefield="#variables.file
</cfif>
</cfloop>
(/Upload_action.cfm)
My question is: How do I check the filesize of *every* upload field with CGI.CONTENT_LENGTH with the above code?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The question was "can I determine the filesize before it is uploaded" if I am correct.
I did not say it was impossible, however I did say I don't think you should be using cgi.content_length for this as its the length of the whole page, i.e. file, form fields, html etc.
use cffile.fileSize to determine the file size after it is uploaded.
In regards to "can I determine the filesize before it is uploaded", unfortunately, though my trials with this same problem there is no way of doing this in Coldfusion.
THE WORKAROUND
The way that I had to do it is to upload the file using the CFFILE ACTION="Upload" and then using to read the file uploaded and with FileRead check the size. If it is over the size you specify then delete it with CFFILE ACTION="Delete".
After I had done my own code and had it working, I found a Custom Tag that does it already <CF_FILEUPLOAD> for free. However, the site I got it from has the link there but it is not working right now.
Tag usage:
<cf_FileUpload
directory="#uploaddir#"
weight="300,300,300,300"
nameofimages="Picture1,Pic
nameConflict="makeunique"
accept="#accept#"
default="">
nameconflict: The operation to perform if the uploaded file name already exists.Valid attributes are "makeunique", "overwrite", "error" and "skip". Default is overwrite.
accept: A comma delimited list of file types. This attribute will not be needed if you use the cf_fileupload tag as well.
weight: Required size The maximum size (in bytes) of the file to upload.
nameofimages: The name of the incoming form variable that contains the uploaded file.
directory: A full path for the destination for the file to upload.
As you can see if you have multiple images you can just specify them as a comma delimited list in the nameofimages.
Picture1,Picture2,Picture3
and the weight comma delimited list corresponds to the image
if I had done use 100,20,300,400 as the weight value it would mean that Picture1 can only be a filesize of 100kb, Picture2 can only be a filesize of 20kb, etc.
Although, if you want this tag let me know your email address and I'll send it off to you.
--= m a b a i t =--
I just came across this post, there definitely is a way and using coldfusion to check the file size before uploading, I have a method currently I built that has a hook into java to read the byte array of the neo.tmp file prior to the image ever getting to the server, not only can I read in the filesize but I can also determine the file type without ever having to place it on the server.
Anyway, just thought I'd toss that out there, if anyone's interested I'll post some example code...
Business Accounts
Answer for Membership
by: Tacobell777Posted on 2004-06-12 at 01:28:16ID: 11294903
I don't think the cgi variable you are talking about will giv eyou the filesize, it will give you the size of the html file as far as I'm aware.
To learn the filesize you need to upload the file first, or perform the check with some activex control or java applet probably, with cf you cannot determine the filesize before it uploaded.