To upload a file from a form:
An Example form:
<form method="post" enctype="multipart/form-data"> <input type="file" name="thefile"/> <input type="submit"> </form>
Example 1:
Code to process the form:
<?php
// get the node to store the file under
$images = $GLOBALS["WT"]->getNode("/File/Images");
// store the uploaded file by giving the name of the file control
$file = $images->createChild("wtFile", Array("Field Name" => "thefile"));
?>
Example 2:
You can also limit the types of files that can be uploaded:
<?php
// get the node to store the file under
$images = $GLOBALS["WT"]->getNode("/Files/Images");
$file = $images->createChild("wtFile", Array("Field Name" => "thefile", "Allowed Extensions" => "jpg,jpeg,gif,png"));
if(!$file) {
print "file type not allowed";
}
?>
Example 3:
if the file is an image, you can also resize it on upload:
<?php
$images = $GLOBALS["WT"]->getNode("/Files/Images");
// resize images that are over 200px wide
$file = $images->createChild("wtFile", Array("Field Name" => "thefile", "Allowed Extensions" => "jpg,jpeg,gif,png", "Max Width" => 200));
?>