CFFILE ACTION="Upload"  
 
 

Use CFFILE with the Upload action to upload a file specified in a form field to a directory on the Web server.

Note that the MODE attribute applies only to ColdFusion on Solaris.

 
 
  Syntax  
 
<CFFILE ACTION="Upload"
    FILEFIELD="formfield"
    DESTINATION="directory"
    NAMECONFLICT="behavior"
    ACCEPT="file_extension"
    MODE="permission"
    ATTRIBUTES="file_attributes">

FILEFIELD

Required. The name of the form field that was used to select the file.

Note: Do not use pound signs (#) to specify the field name.

DESTINATION

Required. The destination directory on the Web server where the file should be saved.

Note: The directory does not need to be beneath the root of the Web server document directory.

NAMECONFLICT

Optional. Default is error. Determines how the file should be handled if its name conflicts with the name of a file that already exists in the directory. Valid entries are:

  • Error -- Default. The file will not be saved, and ColdFusion will stop processing the page and return an error.
  • Skip -- Neither saves the file nor throws an error. This setting is intended to allow custom behavior based on inspection of FILE properties.
  • Overwrite -- Replaces an existing file if it shares the same name as the CFFILE destination.
  • MakeUnique -- Automatically generates a unique filename for the upload. This name will be stored in the FILE object variable "ServerFile." You can use this variable to record what name was used when the file was saved.

ACCEPT

Optional. Use to limit what types of files will be accepted. Enter one or more MIME types, each separated by comma, of the file types you want to accept. For example, to allow uploads of GIF and Microsoft Word files, enter:

ACCEPT="image/gif, application/msword"

Note: The browser uses the file extension to determine file type.

MODE

Optional. Defines permissions for an uploaded file in Solaris. Ignored in Windows. Valid entries correspond to the octal values (not symbolic) of the UNIX chmod command. Permissions are assigned for owner, group, and other, respectively. For example:

MODE=644

Assigns the owner read/write permissions and group/other read permission.

MODE=666

Assigns read/write permissions for owner, group, and other.

MODE=777

Assigns read, write, and execute permissions for all.

ATTRIBUTES

Optional. A comma-delimited list of file attributes to be set on the file being uploaded. The following file attributes are supported:

  • ReadOnly
  • Temporary
  • Archive
  • Hidden
  • System
  • Normal

If ATTRIBUTES is not used, the file's attributes are maintained. If Normal is specified as well as any other attributes, Normal is overridden by whatever other attribute is specified.

Individual attributes must be specified explicitly. For example, if you specify just the ReadOnly attribute, all other existing attributes are overwritten.

 
 
  Examples  
 

The following example will create a unique filename if there is a name conflict when the file is uploaded:

<CFFILE ACTION="Upload" 
    FILEFIELD="FileContents" 
    DESTINATION="c:\web\uploads\" 
    ACCEPT="text/html" 
    NAMECONFLICT="MakeUnique">

 
 
  UNIX Examples  
 

This following three examples show the use of the MODE attribute for UNIX. The first example creates the file /tmp/foo with permissions defined as rw-r-r-- (owner=read/write, group/other=read).

<CFFILE ACTION="Write" 
    FILE="/tmp/foo" 
    MODE=644>

This example appends to the specified file and makes permissions read/write (rw) for all.

<CFFILE ACTION="Append" 
    DESTINATION="/home/tomj/testing.txt" 
    MODE=666  
    OUTPUT="Is this a test?">

The next example uploads a file and gives it rwx-rw-rw permissions (owner/group/other=read/write).

CFFILE ACTION="Upload" 
    FILEFIELD="fieldname" 
    DESTINATION="/tmp/program.exe" 
    MODE=755>



 
 
BackUp LevelNext
 
 

allaire     AllaireDoc@allaire.com
    Copyright © 1998, Allaire Corporation. All rights reserved.