Making Sure an Upload Worked ColdFusion Help

Often, it is necessary to make sure the upload action was successful. Whenever AaION-· UPLOAD·is used, a range of variables with the Fi 1e. prefix are created, providing information about the success or failure of a file upload operation. These variables can be used in your template like other variables and parameters. The available variables are outlined in the following list:

File. AttemptedServerFile Name under which ColdFusion initially tried saving the file.

File. ClientDirectory Directory in which the uploaded file existed on the user’s computer system.

File.ClientFile The name of the uploaded file on the user’s computer system.

File.ClientFileExt The extension, without the leading dot (for instance, htm and not. htm), of the uploaded file on the serfs computer system.

File. (ClientFileName The name, without the extension, of the uploaded file on the user’s computer system.

File. ContentSubType MIME subtype of the uploaded file (the part after the slash in the MIME type).

File.ContentType MIME type of the uploaded file.

File. DateLastAccessed Last access date and time of the uploaded

File.FileExisted. Specifies whether the uploaded file already existed in the specified directory on the ColdFusion server. Possible values are YESand NO

File.FileSbe The size of the uploaded file.

File.FileWasAppended Specifies whether the uploaded file was appended to an existing file on the ColdFusion server. Possible values are YESand NO.

File. FileWasOverwritten Specifies whether the uploaded file overwrote an existing file on the Coldfusion server. Possible values are YESand NO.

File. FileWasRenued Specifies whether the uploaded file was renamed before being saved on the Cold Fusion server. Possible values are YESand NO.

File. FileWasSaved Specifies whether the uploaded file was saved on the ColdFusion server. Possible values are YESand NO.

File.·OldFileSize The size of a file that was overwritten by the uploaded file.

File. ServerDirectory The directory in which the uploaded file was saved on the ColdFusion server.

File.ServerFile The filename under which the uploaded file was saved on the ColdFusion server.

File. ServerFileExt The extension of the filename, without the leading dot (for iJlstance, h,tmand not . htm), under which the uploaded file was saved on the Coldfusion server.

File.ServerFileNue The filename, without the extension, under which the uploaded file was saved on the ColdFusion server.

File. TiMCreated The time that the uploaded file-was saved on the ColdFusion server.

File.Ti_LastModified The time that the uploaded file was last modified.

Manipulating Files on the Server

After uploading files, the next most common set of operations on files is moving, renaming, copying, and deleting them using the CFFILE tag. Moving, renaming, and copying are handled in essentially the same way, so we will present them together, followed by a look at file deletion using ColdFusion.

Moving, Renaming, and Copying Files

Moving, renaming, and copying files are simple operations, using the CFFILE tag. These actions are performed using the ACTION-‘ MOVE, ACTION-‘ RENAME•, and ACTION- COpy’ attributes, respectively.

In all three cases, the same three additional attributes to the CFFILEtag are available: SOURCE Specifies the file (including full path) on which to perform the action. This is a required attribute.

DESTINATION Specifies the destination file (including full path) when renaming or copying, or the destination directory when moving. Depending on the action being performed, the source file will be moved to the specified directory, renamed to the specified file, or copied to the specified file. This is a required attribute.

ATTRIBUTES This attribute mirrors the ATIRIBUTESattribute available when using

ACTION=U” PLOAD.”It specifies a comma-delimited list of file attributes that will be applied to the file resulting from a move, rename, or copy action. The comma-delimited list can be chosen from the following list of file attributes: ReadOnl y, Temporary, Archi ve, Hidden, System, and Normal. When this attribute is not used, the original source file’s attributes are maintained for the destination file. Anyone with a modest familiarity with the DOS command prompt or basic Unix file manipulation commands should be able to understand the use of the CFFILE tag to move, rename, or copy files.

Consider the DOS move, rename, and copy commands. In all cases, these commands take two arguments: the first corresponds to the SOURCEattribute in the CFFILE tag, and the second tozhe DESTINATIONattribute in the CFFILEtag.

 Deleting Files

Deleting a file using the ACTION=” DELETE” attribute of CFFILE is even easier than copying, moving, and deleting because only one required attribute needs to be used. The FILE attribute is used to specify the filename (with its complete path) of a file to delete from the ColdFusion server. The command would be written as the following:

<CFFILE ACTION=’OELETE’
FILE-‘c:\temp\test.txt’)

Posted on November 14, 2015 in File Management

Share the Story

Back to Top
Share This