^file::create[format;name;content]
^file::create[format;name;content;options][3.4.0]
Constructs an object of class file, with specified name and content.
Format defines format of created file. For now it can be only text.
Options-hash, in which you can specify $.charset[charset] or $.content-type[...] [3.4.1]
Note: if there is a need to save file to server disk, there is simple way: ^string.save[ ].
Example of export data in XML format
#export.html
^connect[connection string]{
$products[^table::sql{select product_id, name from products}]
$file[^file::create[text;export.xml;^untaint[xml]{<?xml version="1.0" encoding="$request:charset"?>
<products>
^products.menu{<product id="$products.product_id" name="$products.name"/>}
</products>
}]]
$response:download[$file]
}
When this document is opened then file export.xml is created and browser suggests visitor to save it.
Sample result: