Working with Files

Documentation home

Uploading files from a browser 1

Creation of PDF document files 3

Creation of XML files 4

Emailing files as attachments 4

FPL functions 4

 

See also:

Working with Sequences

Working with XML Resources

FPL Script Command Syntax

Ebase Startup Parameters

 

Ebase has a number of facilities to facilitate the handling and processing of physical files. These include:

 

Uploading files from a browser

 

The upload facility is invoked by using the UPLOAD FPL script command; this command takes no additional parameters. The command results in the display of the upload page as shown below. The texts in this window can be customized or displayed in languages other than English (see below).

 

 

 

 

The user can then either enter the name of the file to be uploaded or press the Browse... button to navigate to it. The Upload button uploads the file to the server and the Cancel button cancels the upload process. Pressing either the Cancel or Upload buttons returns control to the Ebase form and processing resumes at the script command following the upload command.

 

Uploaded files are saved in the directory specified in the Ufs.fileDirectoryName parameter of UFSSetup.properties. The last portion of the file name will be the name of the file on the client machine with a number added if necessary for uniqueness e.g. the first upload of a file named my_cv.doc will be saved with this name, the second with my_cv1.doc, them my_cv2.doc etc. In addition, any spaces in the file name will be changed to underscores ( _ ) to ensure valid filenames when a Windows file is being saved on a Unix or Linux server.

 

After an upload, the $FILE_NAME system variable is set with the full path name of the uploaded file as saved on the server system. This can then be used to add the file to an email as an attachment, or it can be assigned to other form fields, or can be substituted into a message or email text, or used in any other script commands. If the Cancel button is pressed, $FILE_NAME will contain a null value.

 

In addition the $FILE_NAME_USER system variable is set with the last portion of the file name on the client system e.g. if the user has uploaded C:\My Documents\my_cv.doc, then $FILE_NAME_USER will contain the value my_cv.doc. This is provided so positive feedback can be provided to the user.

 

Here is a sample FPL script that can be used for uploading a single file. This script would typically be activated by an action button on an Ebase form page e.g. with text Click here to upload your CV.

 

// sample upload script

// display the upload page...

upload;

// Processing resumes here after the upload..

// Error message if the Cancel button has been pressed

if [$FILE_NAME = null]

message 'You must upload something';

else

// Show info message if file uploaded successfully

message W, 1013, $FILE_NAME_USER;

set CV_FILE_NAME = $FILE_NAME;

endif

// end of upload script

 

Where Message 1013 has the text: File && uploaded successfully

 

Two additional parameters of UFSSetup.properties can be used to constrain the uploaded documents:

 

Ufs.maxUploadFileSize :    the maximum permitted file size for an upload. This can be specified as nnnM (megabytes) or nnnK (kilobytes) or just a number e.g. 5M or 500K or 600000 (600K). If omitted the default is 1M. Limiting the size of uploadable files helps prevent denial of service attacks where a hacker attempts to crash the server by uploading extremely large files.

 

Ufs.uploadFileTypes : contains a comma delimited list of acceptable file types e.g. doc,xls,ppt. Value all can also be specified and this is the default if this parameter is omitted.

 

!!! Important note: Ebase does not check uploaded files for viruses. Virus checking software should be installed on the server to prevent the uploading and saving of infected files.

 

The texts and messages displayed in the upload window can be customized using the system texts editor available from the Tools menu (Tools  àSystemTexts Editor) in the Ebase Designer. These can also be specified in languages other than English. The upload window texts are shown in the table below.

 

Upload window texts (language English)

 

Text no.

Description

Default supplied text

320

Header text

Please enter the file to be uploaded in the box below or press the Browse button to navigate to the file. Then press the Upload button. Files of all types can be uploaded and the maximum permissible file size is 2MB.

321

File name label

File name

322

Upload button

Upload

323

Cancel button

Cancel

324

Trailer text

Press Upload to upload the file, Cancel to return

325

Stylesheet used for texts

See system texts editor

326

Stylesheet used for error messages

See system texts editor

327

File not found error message

Error: file is empty or does not exist

328

File type not allowed error message

Error: file type is not supported for upload

329

File too large error message

Error: uploaded file exceeds maximum size of

 

 

Creation of PDF document files

 

Two FPL commands print and PDFPrint can be used to generate PDF documents and optionally display these to the end user in popup windows. Both of these commands can additionally save the generated PDF documents. The syntax to achieve this is:

 

print <print resource> save;

print <print resource> save nodisplay;

PDFPrint save;

PDFPrint save nodisplay;

 

The nodisplay option indicates that the PDF documents are created but not displayed to the user.

 

These commands will be result in a file being saved in the directory specified in parameter Ufs.pdfDirectoryName in UFSSetup.properties. File names are generated from the sequence UFS_SAVED_PDF_DOCUMENTS and this sequence can be amended to adjust the file numbers if necessary.  If Ufs.pdfDirectoryName has the value /ufs/generated_pdfs and we are saving the seventh file with this name, the print command will save a file named /ufs/generated_pdfs /<print-resource-name>0000000007.pdf, and the PDFPrint command will save a file named /ufs/generated_pdfs /<formname-printformname>-0000000007.pdf.

 

System variable $FILE_NAME contains the full path of the saved file after issuing either of the above commands.

 

Creation of XML files

 

The write FPL command can be used to create an XML file and system variable $FILE_NAME will contain the full path of the generated XML file after issuing this command. (See Working with XML Resources for more information)

 

Emailing files as attachments

 

Any number of files can be sent as attachments with an email message by using the sendmail command with the syntax:

 

sendmail <email resource> with attachments field1, field2, field3.....;

 

where field1, field2, field3 etc. are form field names (or system variables such as $FILE_NAME) containing the full path of a file to be attached.

 

e.g.

sendmail JOB_APPLICATION_MESSAGE with attachments $FILE_NAME;

sendmail PLANNING_APPLICATION_MESSAGE with attachments FILE1, FILE2, FILE3, FILE4, FILE5;

 

If a form field referenced as an attachment contains no value, it will be ignored by the system. This is designed to provide the ability for the end user to upload any number of documents, for example in support of a planning application. In the second example above, if FILE1, FILE2 and FILE3 contain the file paths of three uploaded files, these three files will be attached to the email message and FILE4 and FILE5 will be ignored.

 

FPL functions

 

The following functions can be used with file processing:

 

deletefile deletes a single file. This is an additional function and may need to be configured.

writetofile writes the contents of a form field to a file. This is an additional function and may need to be configured.

write2CSV writes contents of a form field(s) to a CSV file. This is an additional function and may need to be configured.

osfiles populates a list with the names of all files in a directory.

movefile moves a file on the server to a new location.

fileexists checks whether a file exists on the server.