CFFILE ACTION = "UPLOAD" | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Description
Copies a file to a directory on the server. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Syntax<cffile action = "upload" fileField = "formfield" destination = "full_path_name" nameConflict = "behavior" accept = "mime_type/file_type" mode = "permission" attributes = "file_attribute_or_list"> result = "result_name" |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
See also
cfdirectory |
|||||||||||||||||||||||||||||||||||||||||||||||||||||
History
See the History section of the main cffile tag page.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Usage
After a file upload is completed, you can get status information using file upload parameters. To refer to parameters, use either the cffile prefix or, if you specified an alternate name in the result attribute, the name you specified there. For example, if you did not specify a name in the result attribute, access the fileExisted parameter as #cffile.fileExisted#. If you set the result attribute to myResult, however, access fileExisted as #myResult.fileExisted#. Status parameters can be used anywhere that other ColdFusion parameters can be used.
The following file upload status parameters are available after an upload:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
Example
The following example creates a unique filename, if there is a name conflict when the file is uploaded on Windows: <!--- Windows Example ---> <!--- Check to see if the Form variable exists. ---> <cfif isDefined("Form.FileContents") > <!--- If TRUE, upload the file. ---> <cffile action = "upload" fileField = "FileContents" destination = "c:\files\upload\" accept = "text/html" nameConflict = "MakeUnique"> <cfelse> <!--- If FALSE, show the Form. ---> <form method="post" action=<cfoutput>#cgi.script_name#</cfoutput> name="uploadForm" enctype="multipart/form-data"> <input name="FileContents" type="file"> <br> <input name="submit" type="submit" value="Upload File"> </form> </cfif> |
ACTION | |
Required | |
Type of file manipulation that the tag performs. |
FILEFIELD | |
Required | |
Name of form field used to select the file. Do not use number signs (#) to specify the field name. |
DESTINATION | |
Required | |
Pathname of directory in which to upload the file. If not an absolute path (starting a with a drive letter and a colon, or a forward or backward slash), it is relative to the ColdFusion temporary directory, which is returned by the GetTempDirectory function. |
NAMECONFLICT | |
Optional | |
Default value: "Error"
Action to take if filename is the same as that of a file in the directory.
|
ACCEPT | |
Optional | |
Limits the MIME types to accept. Comma-delimited list. For example, to permit JPEG and Microsoft Word file uploads: accept = "image/jpg, application/msword" The browser uses file extension to determine file type. |
MODE | |
Optional | |
Applies only to UNIX and Linux. Permissions. Octal values of chmod command. Assigned to owner, group, and other, respectively. For example:
|
ATTRIBUTES | |
Optional | |
Applies to Windows. A comma-delimited list of attributes to set on the file. If omitted, the file's attributes are maintained. Each value must be specified explicitly. For example, if you specify attributes = "readOnly", all other attributes are overwritten.
|
RESULT | |
Optional | |
Allows you to specify a name for the variable in which cffile returns the result (or status) parameters. If you do not specify a value for this attribute, cffile uses the prefix `cffile'. For more information, see the Usage section. |