Cffile Parameters
Before we finish with ColdFusion's <cffile>
tag, let's look at some important info regarding this tag.
When you use <cffile>
to upload a file to the server, ColdFusion automatically makes a number of file status parameters available for you for that file. During the upload operation, these parameters are available in the file
scope.
Here are the file status parameters:
Parameter | Description |
---|---|
attemptedServerFile | Initial name ColdFusion used when attempting to save the file. |
clientDirectory | This is the directory where the file is located on the user's computer. |
clientFile | This is the name of the file on the user's computer, including the extension. |
clientFileExt | The extension of the file on the user's computer. Doesn't include a period. |
clientFileName | Name of the file on the user's computer. Does not include the extension. |
contentSubType | MIME content subtype of the saved file. For example, the contentSubType for a Microsoft Word document might be "msword". This may differ slightly depending on your version of Word. |
contentType | MIME content type of the saved file. For example, the contentType for a Microsoft Word document is "application". |
dateLastAccessed | Date and time the file was last accessed. |
fileExisted | Whether the file already existed with the same path. Possible values: Yes/No. |
fileSize | Size of the uploaded file |
fileWasAppended | Whether the uploaded file was appended to another file. Possible values: Yes/No. |
fileWasOverwritten | Whether the file overwrote another file. Possible values: Yes/No. |
fileWasRenamed | Whether the file was renamed to avoid a name conflict. Possible values: Yes/No. |
fileWasSaved | Whether the file was saved. Possible values: Yes/No. |
oldFileSize | If a file is overwritten, this is the size of the file's size before it was overwritten. |
serverDirectory | This is the directory where the file was saved on the server. |
serverFile | This is the name of the file on the server, including the extension. |
serverFileExt | The extension of the file on the server. Doesn't include a period. |
serverFileName | Name of the file on the server. Does not include the extension. |
timeCreated | Time the file was created. |
timeLastModified | Date and time of the last modification to the file. |
Note that 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.
You, as the developer, can make good use these parameters. In the next lesson, we will see how these parameters can be inserted into a database during the upload process.