365 users using DBSP now!
home -> documentation -> language reference -> FILETODISK tag


Description

The FILETODISK element is used to save a file into the server via an HTTP post.


Syntax

<#FILETODISK FILECONTROL="thefilecontrol" PATH="thepath" NAME="thename" | AUTONAME [MAXSIZE="themaxsize"] [ACCEPT="theextensions" | DENY="theextensions"] />

FILECONTROL Specify in thefilecontrol the HTML file input control of your form that will be used to send the file.
PATH Indicate in thepath, the directory in which the file will be stored.
FILENAME If you want that the file be stored with a specific name, set this property with the desired name. Any previously existing file will be rewrited.
AUTONAME Include the AUTONAME property if you want that the file be automatically renamed for avoid rewritings. This function will take the file control name as a prefix, and will append an index to the name, for example: file1, file2, file3… etc.
MAXSIZE Set in themaxsize the maximum size in kilobytes that the file could be in order to be posted to the server. For example: A value 120 indicates that the maximum file size that could be uploaded will be 122880 bytes ( 120 x 1024 bytes ).
ACCEPT Specify in theextensions the valid file extensions accepted for post to the server separated by commas. For example : TXT,ZIP,HTML is a valid value for this property.
DENY Indicate in theextensions the file extensions that most be denied for posting into the server separated by commas. For example : EXE,COM,BAT,DLL is a valid value for this property.


Note: In order to post correctly a file into the server, the property ENCTYPE of the form must be set to multipart/form-data and the method property must be set to POST.


Note: After the file is successfully posted to the server, its name will remain in a variable named as the file control. You could use this variable later on the page for storing a reference to it into a database.

Applications

You could use the FILETODISK tag to upload images, text files or any file that you want to use or publish in your site. One common application is to use this tag for uploading images for a news panel or upload CSV files for batch processing into the server, both using a simple mechanism (HTTP). This could be useful if you don't want to use ftp for any particular reason.

Note: Never grant execution privileges to any folder used for posting your uploaded files. This could allow a malicious user to upload an executable application that takes control of your server or cause irreversible damage to your information, server or network. In fact, don't give execution privileges to any folder except that is absolutely necessary.


Examples

Example 1. Uploading a file to the server via HTTP.

Suppose that you want to upload a file to the server via HTTP. This example shows you how.

Source code


File: examples/PostFile.dbsp

  
    

File to disk example


   

    This form will upload a file to the server. 
    In order to post correctly a file into the server, the property ENCTYPE of the form must be set to multipart/form-data and the method property must be set to POST.
    
   

Select a text file with a size not bigger than 100kb and press the send button. 
   

     
     


     
    
   

    
  



File: examples/PostFile1.dbsp

  
    

File to disk example


   

    <#FILETODISK FILECONTROL="TEXTFILE" PATH="C:\TEMP" ACCEPT="TXT" MAXSIZE="100" AUTONAME/>
    <#IF EXPRESSION="TEXTFILE!=UNDEF">
        The file has been successfully posted with name: <#TEXTFILE/>.
    <#ELSE>
      The control file is empty or the form properties are incorrectly set.
    <#/IF>
  

Test example