FileUploadAll

Description

Uploads all files sent to the page in an HTTP request to a directory on the server.

Returns

An array of struct that provides the file upload status. For details of what the struct contains, see the Usage Section of  cffile action = " uploadAll ".

Function Syntax

FileUploadAll(destination, accept, nameConflict, strict, continueOnError, errors, allowedExtensions)

History

ColdFusion (2018 release) Update 3, ColdFusion (2016 release) Update 10, ColdFusion 11 Update 18: Added the parameter allowedExtensions.

ColdFusion 11: Added continueOnError and errors parameters.

ColdFusion 9.0.1: Added this function.

Parameters

Parameter

Required

Default

Description

destination

Required

 

Path of  directory  in which to upload the file. If not an absolute path (starting with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, returned by the function getTempDirectory.
If the destination you specify does not exist, ColdFusion creates a file with the specified destination name. For example, if you specify the destination C:\XYZ, ColdFusion creates a file XYZ in the C: drive.

accept

Optional

 

Limits the MIME types to accept. It is a comma-delimited list. For example, the following code permits JPEG and Microsoft Word file uploads:"image/jpg,application/msword".

When strict="true"

If the mime type is specified in the accept attribute, the file does not get uploaded if the extension is blocked in the server or application settings.

When strict="false"

If you provide a file extension in the attribute accept, the extension overrides the blocked extension list in the server or application settings. The file then gets uploaded.

If the file that you are trying to upload has it’s extension blocked in the Administrator/Application-level settings, and the mime type is specified in the accept attribute, the file does not get uploaded.

For example,

  • If you have blocked file type CFM in the ColdFusion Administrator and specified accept=".cfm" in the tag, and when you try uploading a CFM file, the file gets uploaded.
  • If you have blocked file type CFM in the ColdFusion Administrator and specified accept=”text/x-coldfusion” in the tag, and when you try uploading a CFM file, the file gets blocked.

Values specified in the attribute allowedExtensions overrides the list of blocked extensions in the server or application settings.

nameConflict

Optional

Error

Action to take if  file  has the same name of a file in the directory.

  • Error: File is not saved. ColdFusion stops processing the page and returns an error.
  • Skip: File is not saved. Permits custom behavior based on file properties.
  • Overwrite: Replaces file.
  • MakeUnique: Forms a unique filename for the upload;  name  is stored in the file object variable serverFile.

continueOnError 

Optional

False

By default, when uploading one of the files fail, the remaining files will not be uploaded. If this value is set to true, file upload continues  evern  after encountering an upload error. A file upload error happens due to the following reasons:

1. Empty file
2. Invalid file type
3. Invalid MIME or extension
4. File already exists

In the case of an upload failure, the error details will be stored in the errors attribute.

allowedExtensions

Optional

 

A comma-separated list of file extensions, which will be allowed for upload.

For example, .png, .jpg, or, .jpeg.

You can use "*" (star) to allow all files, except where you specify the MIME type in the accept attribute.

Values specified in the attribute allowedExtensions override the list of blocked extensions in the server or application settings.

strict

Optional

True

strict="false"

If you provide a file extension in the attribute accept, the extension overrides the blocked extension list in the server or application settings. The file then gets uploaded.

If you provide a MIME type in the attribute accept, and the extension of the file you are trying to upload is blocked in the Administrator/Application-level settings, the file does not get uploaded.

For example,

  • If you have blocked file type CFM in the ColdFusion Administrator and specified accept=".cfm" in the tag, and when you try uploading a CFM file, the file gets uploaded.
  • If you have blocked file type CFM in the ColdFusion Administrator and specified accept=”text/x-coldfusion” in the tag, and when you try uploading a CFM file, the file gets blocked.

strict="true"

If the mime type is specified in the accept attribute, the file does not get uploaded if the extension is blocked in the server or application settings.

For example, if you have blocked file type CFM in the ColdFusion Administrator and specified accept=”text/x-coldfusion” and strict=”true” ,and you try uploading a cfm file, the file does not get uploaded.

Values specified in the attribute allowedExtensions overrides the list of blocked extensions in the server or application settings.

errors

Optional

  cffile .uploadAllErrors

 The name of the variable in which the file upload errors will be stored. Errors will be populated in the specified variable name when continueOnError is true .After the file upload is completed, this tag creates an array of structures that contains upload failure information for each upload failure.

The upload failure information error structure contains the following fields:

  • REASON - The reason for the failure
  • DETAIL - File upload failure detail
  • MESSAGE - A detailed message depicting the failure
  • CLIENTFILE  - Name of the file uploaded from the client's system
  • CLIENTFILEEXT - Extension of the uploaded file on the client system (without a period)
  • CLIENTFILENAME - Name of the uploaded file on the client system (without an extension) 
  • INVALID_FILE_TYPE - If the file mime type or extension is not in the specified accept attribute. If the reason is INVALID_FILE_TYPE, two additional keys will be available in the structure. 
    • ACCEPT: list of mime types or file extensions given in the tag
    • MIMETYPE:  mime  type of the uploaded file
  • EMPTY_FILE - If the uploaded file is an empty file
  • FILE_EXISTS - If any file with the given name already exists in the destination and the  overwritepolicy  is  error .
  • DEST - The destination where  file  is copied
  • FORM_FILE_NOT_FOUND - If the uploaded file is not found on the server.

See also

FileUpload

Usage

cffile action = "uploadAll"

Example

<cfscript>
    destination=GetDirectoryFromPath(GetCurrentTemplatePath());   
    acceptMimes="image/png, image/jpeg, text/x-coldfusion, text/plain, application/xml";
    onConflict="MakeUnique";
    strict = false;
    continueOnErr = false;
    errOnOps = "";
    acceptExtensions = ".png, .cfm";

    fileUploaded = FileUploadAll(destination, acceptMimes, onConflict, strict, continueOnErr, errOnOps, acceptExtensions);
    writeDump(fileUploaded);
</cfscript>

 Adobe

Получайте помощь быстрее и проще

Новый пользователь?