----- Original Message -----
From: "YC Nyon" <[EMAIL PROTECTED]>
> How do I limit a file size that is being upload to my server.
> If it was a 1MB limit, can I stop the process when it goes beyond the
limit
> or must i wait till the process is done and delete it off using the CFFile
> tag.
----------------------------

I always use:

<cfif Val(CGI.CONTENT_LENGTH) GT maxFileSize>
    [return user to form with error]
</cfif>

That CGI var is the total size in bytes of the request that was submitted -
including all the form data, which includes the file. This works fine
unless:

1. Your form contains a *whole* load of text that could really widen the gap
between the total size of the request and the size of the actual file
uploaded (which is unlikely), or

2. You need a really low, specific limit to the file size that would mean
even a bit of text in the accompanying form would make the check too
inaccurate (unlikely again I reckon).

So if you set maxFileSize to 1048576 (= 1MB I think), maybe the user would
upload a file that's a couple of KB short of the maximum, but accompanied by
3 KB of other form data, the file would be rejected - but who wants to be
*that* accurate?

The main thing is, all this can happen before you upload with CFFILE - which
is a slight misnomer, because the file's already on the server, uploaded by
the browser along with the rest of the request. CFFILE merely, AFAIK, copies
the file from server memory to hard disk.

HTH,

- Gyrus

~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- [EMAIL PROTECTED]
work: http://www.tengai.co.uk
play: http://www.norlonto.net
- PGP key available
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

______________________________________________________________________
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to