Monday May 29, 2017

      SteelArrow Basics
      SteelArrow Tags
  SteelArrow Functions
  SteelArrow Objects
  Advanced Topics
  WAS Overview
  Code Samples
  Site Search

Get SteelArrow!     
  File Manipulation    
There are several different tags in SteelArrow for doing file operations. These tags allow the developer to setup secure systems for file uploads, and reading/writing of textual file data.

The FILE tag offers functionality for reading an writing data using an absolute path. To offer a secure version of this tag, its functionality was split in two, between the READFILE and WRITEFILE tags. These tags are a secure solution since they do not allow absolute paths, and instead use paths relative to the directory contianing the script being executed. Though READFILE and WRITEFILE use relative paths, they do not allow the use of '..' (parent directory) or '.' (current directory).

Each of these tags are further secured by having the ability to be disabled on any system. As well, user or group enabling of these tags is possible with system configuration.

Further to this, the IMPORT, READFILE and WRITEFILE tags support virtual directories. These directories can be configured on a per user basis. This allows for the central storage of data across different applications on the server using these tags. If a path (usually specified in the FILE= attribute) begins with the backslash character '\', the file path will be resolved as a virtual one.
(a forward-slash can also be used)

The FILE tag supports the following actions;
RENAME Rename a file
COPY Copy a file
DELETE Delete a file
CREATEDIRCreate a directory
LIST List a directory
SIZE Retrieve size of a directory or file
UPLOAD HTML file upload functionality

The following code snippets show examples of the functionality:

<!--- RENAME a file --->
<SAFILE SRC="oldFile.dta" DEST="newFile.dta"

<!--- COPY a file ---> <SAFILE SRC="origFile.dta" DEST="opyFile.dta" ACTION="COPY">
<!--- DELETE a file ---> <SAFILE SRC="file2delete.dta" ACTION="DELETE">
<!--- CREATEDIR a file ---> <SAFILE SRC="dir2create" ACTION="CREATEDIR">
<!--- LIST directory contents ---> <SAFILE SRC="dir2list" ACTION="LIST" NAME=dirList>
<!--- Retrieve SIZE of a directory ---> <SAFILE SRC="dir2list" ACTION="SIZE" NAME=dirSize>
<!--- Retrieve SIZE of file ---> <SAFILE SRC="file2size.dta" ACTION="SIZE" NAME=fileSize>
<!--- HTML UPLOAD of file ---> <SAFILE FILEDATA=fileField DEST="uploadFile.dta" ACTION="UPLOAD">

Each of the above ACTIONs (excluding LIST and SIZE) may carry a NAME attribute which will receive TRUE or FALSE denoting the success or failure of the requested ACTION.

The UPLOAD action uses a variable as the FILEDATA attribute. To use the UPLOAD action, the HTML form must use an ENCTYPE of "multipart/form-data" and the form must use the POST method.

The following shows an example HTML form and the SteelArrow code for processing this information:

<!--- Example for HTML file upload --->
   <INPUT TYPE="FILE" NAME="upld" SIZE="50">
   <INPUT TYPE="SUBMIT" VALUE="Upload File">

<!--- SteelArrow to handle upload ---> <SAFILE FILEDATA=upld DEST="file.dta" ACTION="UPLOAD">

The above example shows how file upload can be achieved with SteelArrow and standard HTML. The FILEDATA attribute takes as its parameter the named INPUT. This creates a variable called 'upld' that has several parameters, including: MIME content as upld.CONTENT, file size as upld.SIZE, original (complete) file name as upld.NAME, orgianl file extension as upld.EXT, and server file name as upld.SERVERNAME

This offers the developer an opportunity to validate the uploaded file before the FILE tag is used to store the file on the system. As well, the above upload handling code could be written as:

<!--- SteelArrow to handle upload --->

By doing this, the orignal file name is preserved during the upload operation.


WRITEFILE supports similar functionality, but does not support all of those available with the FILE tag. WRITEFILE supports: CREATE, APPEND, CREATEDIR, and UPLOAD. The first two ACTIONS allow a developer to create or append data to an existing textual data file.

See the Guestbook sample for an example of WRITEFILE and READFILE tag use.

READFILE allows textual data to be retrieve from a text data file. It does not support any functionality beyond this.

Copyright © 1998-2004 Tomahawk Technologies Inc.
Privacy Policy