API2, fileman and listfiles objects
Hello. I am wracking my brain trying to use this with the API2 Fileman listfiles query results. Basically, what I am trying to do is get a list of files in a directory and delete the ones older than a week ago. (its part of a backup solution). So I am after the attributes file, mtime and ctime.
In the code snip below, I am able to successfully get the value by using $list->data->file, but it only returns the name of one file. There are multiple files in that directory and I need to get each filename to put it away in an array. If I try to go through each item one by one, it returns nothing. I checked the type and they are all objects so I guess I am doing something wrong.
Below is my code.
The output I am getting is
What am I doing wrong?
$list = $xmlapi->api2_query($account, 'Fileman', 'listfiles', $args);
$files = array();
foreach ($list as $item) {
array_push($files, $item->data->file);
}
array_push($files, $list->data->file);
print_r($files);
print "Count: " . count($files) . "\r\n";
print "Count: " . count($list) . "\r\n";
The output I am getting is
X-Powered-By: PHP/5.5.30
Content-type: text/html
Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] => SimpleXMLElement Object
(
[0] => backup-12.2.2015_19-50-33_atlas514.tar.gz
)
)
Count: 10
Count: 9
What am I doing wrong?
-
never mind. answered by own questions. the code to get it is foreach ($list->data as $item) { array_push($files, $item->file); }0 -
Hello :) I am happy to see you were able to find the solution. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
2 comments