| |
Chapter Nineteen
Reading, Writing, and Deleting Files
File Action
The File action allows you to read, write,
and delete files on the Tango Server machine. Some of the functions you might
want to perform using this action are as follows:
- Store data permanently to disk for later retrieval
(as opposed to variables which are in memory).
- Keep a log file, appending to it when a certain
function gets called in your application file.
- Write HTML files using database-generated data to
your Web server document folder.
- Store data to a file for export to an external
system, providing data navigation.
- Import data from a file from an external system, for
example, daily reports from a mainframe, newswire feeds, and periodic updates
to a third-party supplier.
- Use the action instead of giving FTP access to
deploy (upload) one or two files from a Web site.
- Use the action as an administrative tool to deploy
graphics or as an intranet tool to deploy word processor documents or other
types of documents to the server.
The topics covered in this chapter include:
- setting up a File action
- handling file security.
[back to top]
Setting Up a File Action
You can set up the three types of file operations
using the File action.
Read (the default) allows you to
specify the path and file name of the file you want to read. You also specify
if you want to read the entire file or some part of it, and store the data in a
local variable.
Write allows you to specify the
path and file name of the file to write data to. You also specify what that
data is and, if the file exists, whether the data should be appended to or
overwrite the existing data. You can also store the file name in a local
variable.
Delete allows you to specify the
path and file name of the file you want to delete.
When you drag the File action icon from the Actions
palette, the File action editing window appears.
Note: For any of the editing
fields, you can include value- returning Tango meta tags or drag snippets from
the Snippets Workspace. You can also control+click an editing field to display
a contextual menu of editing commands, including the Insert Meta
Tag command.
Setting Up Read Options
From the File Operation pop-up
menu, select Read, if it is not already selected.
The action editing window changes to show the
options for the Read type operation, which you specify as
follows:
File. The path and file name of
the file you want to display to the user. You must specify the full, absolute
path, not the path relative to the Web server root. For example,
HD:Applications:Simpletext:Foo.
Note: The path specified here
is appended to the value of the absolutePathPrefix configuration
variable. If this configuration variable has a value (in either application or
system scope), this field should contain a path relative to that
location. For more information, see "absolutePathPrefix" in the
Meta Tags and Configuration
Variables manual.
Read. Sets which part of the
file to read. You can choose Entire file, or select one of the
following options:
First. Type the number of bytes to
read from the start of the file.
Last. Type the number of bytes to
read at the end of the file.
Bytes. Type the starting and ending
bytes. If the ending byte you are specifying is the end of the file, you can
select EOF instead.
Store data in local variable.
The name of a local variable to store the read data in.
Note: The read data is also
available as <@COL 1> in the action's Results HTML and is stored
in the local resultSet variable.
If you do not specify a file, the action does not do
anything. In other words, the action behaves like a file exists, but the file
is empty. Specifically, the specified variable is empty.
Setting Up Write Options
From the File Operation pop-up
menu, select Write.
The action editing window changes to show the
options for the Write type operation.
Specify the Write options as
follows:
File. The full, absolute path
and file name of the file you want to write data to.
Note: The path specified here
is appended to the value of the absolutePathPrefix configuration
variable. If this configuration variable has a value (in either application or
system scope), this field should contain a path relative to that
location. For more information, see "absolutePathPrefix" in the
Meta Tags and Configuration
Variables manual.
This file information can also come from a variable
or an argument.
You can also tell Tango to generate a temporary file
by selecting Temporary file from the pop-up menu. If you
select this option, the server creates a temporary file using standard routines
for the operating system.
Data to write. The data to write
to the specified file. For example, you could enter the named post argument for
a form field where the user enters the data to be saved in the specified file,
or enters a file name to deploy.
If file exists. Specify what you
want to do if the file already exists. Select one of the following options:
Append to it appends to the
existing file the data you are writing.
Overwrite it replaces the existing
data in the file with the data you are writing.
Generate an error generates an
error message on execution.
File Attributes (Mac OS type and
creator codes) TEXT and R*ch, which specify a BBEdit text
file, are the default values for new files created with the Write action. They
are also the values used by the server if either field evaluates to empty.
Tango Server uses the first four characters of each field (after substitution).
If you specify fewer than four characters, the value is space padded to the
end.
Store file name in local
variable. The name of a local variable in which to store the path and
file name of the file written to. You would use this option when you write data
to a temporary file.
Note: The read data is also
available as <@COL 1> in the action's Results HTML and is stored
in the local resultSet variable.
Setting Up Delete Options
From the File Operation pop-up
menu, select Delete.
The action editing window changes to show the options
for the Delete type operation.
In the File field, specify the
full, absolute path, and file name of the file to delete.
Note: The path specified here
is appended to the value of the absolutePathPrefix configuration
variable. If this configuration variable has a value (in either application or
system scope), this field should contain a path relative to that
location. For more information, see "absolutePathPrefix" in the
Meta Tags and Configuration
Variables manual.
[back to top]
Handling File Security
|
For more information, see
"Configuring Tango Server".
|
You can specify that file reads, writes, and
deletes only take place in a specified directory of Tango Server using the
absolutePathPrefix configuration variable. Using this configuration
variable to set the path for file reads, writes, and deletes ensures that users
cannot access directories other than the specified ones when using the File
action.
File reads, writes, and deletes are enabled in Tango
by default. If you want to disable (or enable) these features, you can do so by
changing the following options in the Tango 2000 Configuration Manager (the
config.taf application file), in the Feature Switches
screen:
fileReadSwitch
fileWriteSwitch
fileDeleteSwitch
|