dfcii
dfcii

Reputation: 21

How can I limit the size of a file when uploading with cffile action="uploadall"?

I'm modifying an application written by someone else. It uses the ColdFusion

<cffile action="uploadall"

How can I check and limit the size on an individual file basis when uploading multiple files?

Upvotes: 2

Views: 317

Answers (1)

rrk
rrk

Reputation: 15846

You will get the uploaded files' details in an Array. You can loop over them and do the file size validation logic independent from cffile tag.

<cffile
  action="uploadall"
  destination="#GetTempDirectory()#"
  nameconflict="MakeUnique"
  result="fileUploaded"
>
<cfset invalidFiles = []>
<cfloop array="#fileUploaded#" item="item">
  <cfif item.fileSize GT sizeLimitInMB*1024*1024>
    <cfset arrayAppend(invalidFiles, {
      'fileName': item.clientFile
    })>
     <!--- You can remove the file manually from here. --->
  </cfif>
</cfloop>
<cfreturn invalidFiles> <!--- Or do anything your business logic require --->

Upvotes: 1

Related Questions