writefile

[writefile] functions allows you to perform a wide variety of tasks, from copying a purchased eBook to a special folder for downloading, to placing an uploaded file on your server.
[writefile file=saved_files/new_filename.txt&secure=f]
  Write this info into new_filename.txt
[/writefile]
Text is written exactly as in the template; it is not interpreted by the browser. Tabs, returns and multiple spaces will be written as is. However, the text WILL be interpreted by WebDNA first, so you may use variables or any WebDNA code necessary to create your text.

Parameters

ParameterDescription
pathThe path to where the file is to be written, including the new file's name
secure(optional) t or f - the file will be written using the permissions preference set in WebDNA preferences

If a file by the same name exists, [writefile] will overwrite it. [writefile] is also used to handle uploaded files, such as jpgs, pdf, or any other format.

Example WebDNA code:
[writefile file=saved_files/filename-[date %Y%m%d].txt&secure=f]
  Write this info into the new file and the date is [date] at [time].
  The browser that was used to create this file was [browsername]
[/writefile]
The text file "filename-2021-09-03.txt" is created inside the folder "saved_files" and the text is inserted:

Write this info into the new file and the date is 09/03/2022 at 16:45:33.
The browser that was used to create this file was Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Safari/605.1.15

Notice that any WebDNA [xxx] tags inside the [writefile][/writefile] context are substituted for their real values before being written to the file. You may specify a full or partial URL to the file, as in "/some-folder/file.txt" or "local-folder/file.txt."

Static webpages or even dynamic pages can be generated if <!--HAS_WEBDNA_TAGS--> is added at the begining of the file. WebDNA can literally autogenerate new programs. See [raw] context.

See also:
[appendfile], [copyfile], [movefile], [deletefile].