Skip to main content
Known Participant
February 26, 2007
Question

How to check file size on upload? In case file is massive...

  • February 26, 2007
  • 12 replies
  • 1624 views
Hi, I have an upload file button on my page, is there a way to check a file size before allowing user to upload file. Right now, if a user uploads a huge file (5 gigs), it would crash is there a file to somehow stop them? I've researched forums and all say that you have to first upload the file and then check the file size with cffile, but is there another way?

Thanks so much,
c
This topic has been closed for replies.

12 replies

Known Participant
March 6, 2007
Hi billdimit, thanks for your code, I tried it out and it finds the files size but if the file is huge (1 gig) then I get "The page cannot be displayed", I think this may be because server cannot handle such a large file?

Thanks,
C
Known Participant
March 5, 2007
Thank you for your comments, billdimit and michaelmuller, I will try the code out on my end.

Thanks again,
C
Inspiring
March 5, 2007
Maybe this code helps.

<cfscript>
function FileSize(filename){
var theFile = createObject("java", "java.io.File");
theFile.init(JavaCast("string", filename));
return theFile.length();
}
</cfscript>
<cfif FileSize(form.fileFieldName) LT 2000000> <-- file up to 2 MB--->

</cfif>
Inspiring
March 5, 2007
Maybe this code helps.
Here is the code:
<cfscript>
function FileSize(filename){
var theFile = createObject("java", "java.io.File");
theFile.init(JavaCast("string", filename));
return theFile.length();
}
</cfscript>
<cfif FileSize(form.fileFieldName) LT 2000000> <-- file up to 2 MB--->

</cfif>
Known Participant
March 2, 2007
And to continue my vamp... very large file downloads don't work either. Either IIS or IE has a 2gb limit on downloads. Yeah, sure, you say "WTF, is he kidding?" well, I remember not too long ago dialing into a BBS with a 2400 baud modem and thinking a 5MB file was ludicrous. 2gb over Verizon's new FIOS will take very little time. We need a solution that doesn't involve FTP, unless CF can solve it with a Java FTP solution ( CFDOWNLOAD? )
Known Participant
March 2, 2007
Specifically, this is a feature request I just sent in:

CFUPLOAD

Launches a java applet on client side to allow multiple file uploads, with certain restrictions (ie; max number of files, total size, etc) and submit either as http to a single thread handler for WHOLE SERVER (so many simultaneous very large uploads, ie 1gb each, don't take down the server handles) or ftp.

Why is this important? File sizes are getting larger and larger and there's more and more video on the Internet. We need an easy way of dealing with this. Solve it for us.

Also, I hear tell that there's going to be image manipulation tags in v8. Excellent. Can you also put in some simple video manipulation tags, such as discovering the x y size of the video and grabbing a thumbnail frame?
Known Participant
March 2, 2007
I think that previous conversation was started by me. We eventually went with a Java FTP applet solution by UltimateFTP. Because it's FTP you don't have to worry about http uploads or overloading CF Server stack. Also, that applet allows you to limit the file size that is uploaded. Unfortunately it is very expensive... around $1200 or so. There are other FTP applet solutions out there, like RAD Uploader (which also has a neat http solution that can go around CF) but there were other constraints in my project.

Hopefully CF will take care of this in v.8 since files are getting larger and larger. I envision a nice cfupload form element that creates a nice Java browse applet with the appropriate bells and whistles (including xfer resume) and is handled by a single thread for ALL upload requests on the server. That would be sweet.

Mik
Inspiring
February 26, 2007
The last time this topic came up on these forums, someone pointed out a
Flash widget that would give you control like this and more to uploading
files. I have never tried it, but it looked kind of interesting when I
glanced at it.

Unfortunately I don't remember anything about it anymore. I would hope
searching the archives and|or Google turn up something. Good Luck.
Participating Frequently
February 26, 2007
Some uploading tools available here:

http://www.cftagstore.com

Unfortunately, because of the nature of HTTP protocol, the safest solution is to limit the size of upload on the server side with "the crash page" by setting limit on HTTP request as a Web-server property or a CF property. There is also CFX tag similar to ASPUpload.
Known Participant
February 26, 2007
Hi all, thank you all for you comments. Currently if the file is too big, I get a server error page and the file is never uploaded so I never even get a chance to check on file properties...
Does anyone have a client-side solution to this? I found one that works only in IE that worries me, does anyone have a sample for all browsers (ie, firefox, netscape...) ?

Thanks so much,
C
Inspiring
February 26, 2007
To do this before the upload happens - you are looking at client side
solutions. JavaScript, Active X and Flash are possible client side
technologies that will help you with this.