How To The Write `<cffile action=”uploadAll”>` Function In ColdFusion?
Description:-
Copies all files sent to the page in an HTTP request to a directory on the server.
<cffile
action = "uploadAll"
allowedExtensions = "comma-separated list of file extensions"
destination = "full pathname"
accept = "list of MIME types"
attributes = "file attribute or list"
mode = "permission"
nameConflict = "behavior"
result = "result name"
ContinueOnError = "true|false"
Errors = Variable in which the file upload errors will be stored."
strict = "true|false"
>
Attributes:-
action
:- This is a required argument for the type of file manipulation the tag performs.
allowedExtensions
:- This is a non-required argument, A comma-separated list of file extensions, which will be allowed for upload.
destination
:- This a required argument, location
path of the directory in which to upload the file.
accept
:- This is a non-required argument, we can limit the MIME types to accept. It is a comma-delimited list.
attributes
:- This is a non-required argument, that applies to Windows. A comma-delimited list of attributes to set on the file. the values are:-readOnly
hidden
normal
mode
:- This is a non-required attribute and applies only to UNIX and Linux. Permissions. Octal values of UNIX chmod command. Assigned to owner, group, and other, respectively.644
:- assigns read/write permission to the owner; read permission to group and others.777
:- assigns read/write/execute permission to all.
nameConflict
:- This is a non-required argument, this will operate if the filename is the same as that of a file in the directory.
ContinueOnError
:- This is a non-required argument, by default, when uploading a file fails, the remaining files will not be uploaded. If this value is set to true, file upload continues even after encountering an upload error.
Errors
:- This is a non-required argument, 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 contain upload failure information for each upload failure.
result
:- This is a non-required argument, this allows you to specify a name for the variable which cffile
returns the result (or status) parameters. If you do not specify a value for this attribute, cffile
use the prefix cffile
.
strict
:- This is a non-required argument,
for false
value 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 true
value 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.
Unlike cffile action="upload"
, which uploads only one file at a time cffile action="uploadall"
uploads multiple files thereby eliminating the need to code multiple cffile action="upload"
statements.
Example:-
<cfform action="#cgi.script_name#" enctype="multipart/form-data">
<cfinput type="file" name="attachment1">
<cfinput type="file" name="attachment2">
<cfinput type="file" name="attachment3">
<cfinput type="submit" name="submit" value="Upload All">
</cfform>
<cfif isdefined("form.submit")>
<cffile
action = "uploadall"
destination = "#expandpath(".")#"
nameconflict = "MakeUnique"
accept = "image/png,image/gif,.png,.gif"
strict = "true"
result = "fileUploaded"
allowedextensions = ".png,.gif,.cfm"
>
<cfloop array="#fileUploaded#" item="item">
<br><cfdump var="#filegetmimetype(item.serverdirectory&'/'&item.serverfile)#">
<br><a href="<cfoutput>#item.serverfile#</cfoutput>">
<cfoutput>#item.serverfile#</cfoutput>
</a>
</cfloop>
</cfif>