Jump to content

AtkFileAttribute

From NusaATK

Attribute: atkFileAttribute

API docs | Flags

List of other attributes

atkFileAttribute screenshot

See also the tutorial about Image_processing_with_the_atkFileAttribute

Description

The atkFileAttribute allows the management of files as attributes. They can be uploaded, replaced, and removed - users can also choose from a list of already-uploaded files.

Params

$name: Name of the attribute $dir: Can be a string with the Directory with images/files or an array with a Directory and a Display Url $flags: Flags for this attribute $size: Filename size

Initial value

If you want the attribute to display a default file when adding a new record, then you might want to add an entry to the initial values array like in this example:

function initial_values()
{
  return array(
    "avatar" => array("filename" => "myavatar.jpg")
  );
}

Note that of course the file myavatar.jpg needs to be present in the specified directory.

Descriptor

If you use an atkOneToManyRelation in combination with the atkFileAttribute and you want to show to files, you get an array as result. This is an example that shows the photo's that are uploaded with the atkFileAttribute(named "photo"):

public function descriptor_def() 
{
	return "<img src=\"../path/to/file/[photo.filename]\" />";
}

Examples

Adding an attribute "filename" which uses a config setting for its path and does not allow selection of previously uploaded files.

$this->add(new atkFileAttribute("filename", atkconfig('images_dir'), AF_FILE_NO_SELECT));

For more attribute flags, look at Attribute_Flags#atkFileAttribute - this is a very flexible attribute.