CFLib.org – Common Function Library Project

getUploadData()

Last updated June 23, 2010

author

David Boyer

Version: 0 | Requires: CF8 | Library: UtilityLib

Description:
Without touching "cffile action='upload'" this function can give you all the information you need about any uploads. This includes the size, original name, temporary name, content type and extension.

Return Values:
Returns a struct.

Example:

<cfdump var="#getUploadData()#" />

Parameters:

No arguments.

Full UDF Source:

/**
 * Returns a structure containing upload information.
 * 
 * @return Returns a struct. 
 * @author David Boyer (dave@yougeezer.co.uk) 
 * @version 0, June 23, 2010 
 */
function getUploadData() {
  var local = {};
  local.result = {};
  if (cgi.request_method Eq 'post') {
    local.uploads = form.getPartsArray();
    if (StructKeyExists(local, 'uploads')) {
      local.count = ArrayLen(local.uploads);
      for (local.u = 1; local.u Lte local.count; local.u++) {
        local.info = GetFileInfo(form[local.uploads[local.u].getName()]);
        local.result[local.uploads[local.u].getName()] = {
          tempFileName = form[local.uploads[local.u].getName()],
          originalName = local.uploads[local.u].getFileName(),
          contentType = local.uploads[local.u].getContentType(),
          filesize = local.info.size,
          ext = ListLast(local.uploads[local.u].getFileName(), '.')
        };
      }
    }
  }
  return local.result;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson