Link to home
Start Free TrialLog in
Avatar of lifegauge
lifegauge

asked on

Check filesize before CFFILE upload

Currently, 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" enctype="multipart/form-data" method="post">
    <cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
      <cfset filename = "file" & #i#>
      <input type="File" name="<cfoutput>#variables.filename#</cfoutput>" /><br />
    </cfloop>
     <input type="Submit" name="upload" value="upload" />
 </form>
(/Upload.cfm)

(Upload_action.cfm)
<cfloop index="i" from="1" to="#variables.numberoffields#" step="1">
    <cfset filename = "form.file" & #i#>
    <cfif evaluate(variables.filename) neq "">
       <cffile action="UPLOAD"
          destination="c:cfusionmxwwwroottestfiles"
          nameconflict="OVERWRITE"
          filefield="#variables.filename#">
     </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?
Avatar of Tacobell777
Tacobell777

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.
Avatar of lifegauge

ASKER

It is possible, as mentioned above, I'm using it to determine the filesize of 1 field now.
ASKER CERTIFIED SOLUTION
Avatar of Tacobell777
Tacobell777

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you don't need FileRead the size is already available to you after using upload, cffile.fileSize as I said before in my answer.
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...
I have this problem as well and am interested in trailblazzyr55's solution.  Can you post the example code?  THANK YOU.