2

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?

rrk
  • 15,677
  • 4
  • 29
  • 45
dfcii
  • 21
  • 1

1 Answers1

1

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 --->
rrk
  • 15,677
  • 4
  • 29
  • 45
  • 1
    I believe this answer is based on checking the file size after they have been uploaded. This question, https://stackoverflow.com/questions/7497404/get-file-size-before-uploading, shows how to do it beforehand. Mind you, it's for a single file, not multiple ones as is the case for this question. – Dan Bracuk Aug 21 '21 at 14:21