ColdFusion 9.0 Resources |
cffile action = "upload"Syntax<cffile action = "upload" destination = "full pathname" fileField = "form field" accept = "MIME type|file type" attributes = "file attribute or list" mode = "permission" nameConflict = "behavior" result = "result name"> Note: You
can specify this tag’s attributes in an attributeCollection attribute
whose value is a structure. Specify the structure name in the attributeCollection attribute
and use the tag’s attribute names as structure keys.
Attributes
UsageAfter 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. When you use a cfform tag or an HTML form tag to submit the form with the file to be uploaded, specify enctype="multipart/form-data" in the tag, as shown in the example for this tag. By default, ColdFusion MX 7 sends the form with the encoding type of application/x-www-form-urlencoded, which causes an error in the cffile tag. The result attribute allows functions
or CFCs that get called from multiple pages at the same time to
avoid overwriting the results of one call with another. Note: The file prefix is deprecated,
in favor of the cffile prefix. Do not use the file prefix
in new applications.
If your page is uploading
a file that was selected on a form or was otherwise sent to your
page via a multipart/form-data HTTP message, you can determine the approximate
size of the file by checking the value of the CGI.content_length variable.
This variable includes the file length plus the length of any other
request content. The following file upload status parameters are available after an upload:
Note: File status parameters
are read-only. They are set to the results of the most recent cffile operation.
If two cffile tags execute, the results of the
second overwrite the first, unless you have specified a different
result variable in the result attribute.
ExampleThe 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> |