Getting the Attributes of a File

Permalink 1 user found helpful
Can anyone help?

I want to grab some information about each file I have.

current code contains a filtered fileset;

Loader::model('attribute/categories/file');
foreach($results as $fobj) {
   $at1 = FileAttributeKey::getByHandle('title');
   //I thought the following would do it
   $title = $fobj->getAttributesValues($at1);
   //I Have tried
   //$title = $fobj->getAttributesValues('title');
}

I dont seem to be able to get it right, I want to be able to get a list of attributes associated with the file then pull back its value.

I can work out that the getAttributes needs a file object and the $fvID but how do I work that out?.

Or the getAttributeValue uses the $avID, where can I grab that from??

TheRealSean
 
TheRealSean replied on at Permalink Best Answer Reply
TheRealSean
Whoop whoop
Ok I think I have this one,

In order to Call an attribute on a file you can not use the same call as you can on a collection you need to use a static call to the

File Attribute class

First create/get a file object then for each file you want to get the information for use

if(is_object($fobj)){
Loader::model('attribute/categories/file');
//using $fobj as the object
//$fobj->fID = The id of the file in question
//$fobj->fvID = The version of the file to use
$attribs = FileAttributeKey::getAttributes($fobj->fID,$fobj->fvID);
//$attribs returns a private object so in order to access you need to use
$attribute_value = $attribs->getAttribute('$attribute');
//where '$attribute' is your attribute handle
}
fjhadd replied on at Permalink Reply
fjhadd
Hi:
I m trying to use this solution but whats those this mean,
"First create/get a file object then for each file you want to get the information for use"

I am have a PDF file list. I create a file attribute for the PDF thumbnails so i can manually insert the thumbnails for each pdf file.
do you know how can i get this attribute SRC
TheRealSean replied on at Permalink Reply
TheRealSean
In order to get the file returned as an object you will need to use the c5 file class

You will need to kow the id of the file you can would like information about,
//the following will get a file object and return it as fobj
$fobj = File::getByID($fileID);


There is more information about this here
http://www.concrete5.org/documentation/developers/files/files-and-f...