File

Manages interactions with server files.

Component Signature

<bx:File action=[string]
file=[string]
mode=[string]
output=[string]
addnewline=[boolean]
attributes=[string]
charset=[string]
source=[string]
destination=[string]
variable=[string]
filefield=[string]
nameconflict=[string]
accept=[string]
result=[string]
fixnewline=[boolean]
cachedwithin=[numeric]
result=[string] />

Attributes

Atrribute
Type
Required
Description
Default

action

string

true

The action to take. One of: append, copy, delete, move, read, readbinary, rename, upload, uploadall, write

file

string

false

The file to act on

mode

string

false

The mode to open the file in

output

string

false

The output of the action

addnewline

boolean

false

Add a newline to the end of the file

false

attributes

string

false

Attributes to set on the file

charset

string

false

The character set to use

utf-8

source

string

false

The source file

destination

string

false

The destination file

variable

string

false

The variable to store the result in

filefield

string

false

The file field to use

nameconflict

string

false

What to do if there is a name conflict

error

accept

string

false

The accept header

result

string

false

The result of the action

fixnewline

boolean

false

Fix newlines

false

cachedwithin

numeric

false

The time to cache the file within

result

string

false

The result of the action

Examples

Script Syntax - Write

File Write

Run Example

Script Syntax - Append

File Append - There is no fileAppend() so we access the file and use fileWriteLine()

Run Example

Script Syntax - Read

File Read

Run Example

Result: Here's some content for my file. Here's some new content.

Script Syntax - Read Binary

File Read Binary

Script Syntax - Rename

File Rename - Since there is no fileRename(), fileMove() works just as well

Script Syntax - Copy

File Copy

Script Syntax - Move

File Move

Script Syntax - Delete

File Delete

Run Example

Tag Syntax (action=write)

Write the contents of a variable to a file.

Tag Syntax (action=append)

Append content to the end of a file.

Tag Syntax (action=read)

Read a file into a variable

Tag Syntax (action=readBinary)

File Read Binary

Tag Syntax (action=rename)

Rename a file

Tag Syntax (action=copy)

Copy a file

Tag Syntax (action=move)

Move a file

Tag Syntax (action=delete)

Delete a file

Tag Syntax (action=upload)

Upload the file contained in the myFile field. Always upload to a directory outside of the webroot, validate the file extension, file content and then only if necessary copy it back to the web root.

Tag Syntax (action=upload) with accept

CF10+ Checks file extensions against a whitelist of allowed file extensions. You must set strict=false when specifying a file extension list.

Tag Syntax (action=uploadall)

Upload all files in the form scope.

Last updated

Was this helpful?