SabreDAV Client - using propfind to list properties

2,102 views
Skip to first unread message

ahm...@gmail.com

unread,
Apr 22, 2013, 8:44:41 AM4/22/13
to sabredav...@googlegroups.com
Hi evert,

I am testing SabreDAV client to list a SabreDAV server folder content, it return an array as next:

################################
Array ( [/dav/server.php/] => Array ( ) [/dav/server.php/file.txt] => Array ( [{DAV:}getcontentlength] => 16 ) [/dav/server.php/myfiles/] => Array ( ) [/dav/server.php/txtper.txt] => Array ( [{DAV:}getcontentlength] => 293 ) [/dav/server.php/webdav.rtf] => Array ( [{DAV:}getcontentlength] => 102822 ) )
################################

client.php
######################
<?php
include 'lib/Sabre/autoload.php';

$settings = array(
    'baseUri' => 'http://localhost/dav/server.php/',
'userName' => '****',
    'password' => '********',
);
$client = new Sabre\DAV\Client($settings);
// Will do a GET request on the base uri
// $response = $client->request('GET'); 
// $response = $client->request('HEAD', 'stuff');
//$response = $client->request('PUT', 'file.txt', "New contents !!!");
//$response = $client->request('DELETE', 'file.txt', null, array('If-Match' => '"12345765"')); 
//var_dump($response); 

$files = $client->propfind('/dav/server.php/', array( '{DAV:}getcontentlength' ), 1); 
print_r($files);

?>
######################

I want to get the value of each propertie for each node and display them on a table as following

name |  length  |  type  |  last modified

file1   |  20 KB  | file     |  FEB 02 2013

Please help me to do that.dealing with array result of a propfind giving me an example.

Regards,

miska

Evert Pot

unread,
Apr 22, 2013, 1:55:49 PM4/22/13
to sabredav...@googlegroups.com
Hi Miska,
Are you asking how to use arrays in PHP?
If so:

Read the PHP manual:

http://php.net/manual/en/language.types.array.php
http://php.net/manual/en/control-structures.foreach.php

Having a basic knowledge of how PHP works is pretty much required when working with sabredav.

Evert

ahm...@gmail.com

unread,
Apr 23, 2013, 9:04:10 AM4/23/13
to sabredav...@googlegroups.com
Hi, Tanks Evert,
I know how to use arrays in php but looking for a client request that can return children for all sub folders of my public folder, for example in my array result bellow there are a sub folder named "/myfiles" which contain some files, i want this sub folder to be listed.

Regards

Evert Pot

unread,
Apr 23, 2013, 9:07:29 AM4/23/13
to sabredav...@googlegroups.com
On Apr 23, 2013, at 2:04 PM, ahm...@gmail.com wrote:

> Hi, Tanks Evert,
> I know how to use arrays in php but looking for a client request that can return children for all sub folders of my public folder, for example in my array result bellow there are a sub folder named "/myfiles" which contain some files, i want this sub folder to be listed.

So do you want to do something like this?

$result = $client->propfind('/dav/server.php/myfiles', array(
'{DAV:}getcontentlength',
'{DAV:}getlastmodified',
'{DAV:}resourcetype'
));

?


Evert

ahm...@gmail.com

unread,
Apr 23, 2013, 10:08:43 AM4/23/13
to sabredav...@googlegroups.com
Hi,
Ok Thanks,
Just that i need !, so, by using propfind i could use any path in my baseuri as parameter ?
 
Regards,
miska

Evert Pot

unread,
Apr 24, 2013, 8:59:18 AM4/24/13
to sabredav...@googlegroups.com
On Apr 23, 2013, at 3:08 PM, ahm...@gmail.com wrote:

> Hi,
> Ok Thanks,
> Just that i need !, so, by using propfind i could use any path in my baseuri as parameter ?

Yea.. the propfind method has 3 arguments:

1. The url you want to know properties of
2. The list of properties you want to know
3. The depth. Use 0 for just the $url argument, use 1 if you also want to know what's in the collection.

Evert

ahm...@gmail.com

unread,
Apr 24, 2013, 12:00:55 PM4/24/13
to sabredav...@googlegroups.com


Le mercredi 24 avril 2013 13:59:18 UTC+1, Evert Pot a écrit :
On Apr 23, 2013, at 3:08 PM, ahm...@gmail.com wrote:
Hi,
Ok, but i have problems with some properties:

resourcetype:
##############

Catchable fatal error
: Object of class Sabre\DAV\Property\ResourceType could not be converted to string
   
###############

displayname and getcontenttype props are not displayed,

my file content:

##########################################
<h2>Page d'accueil WebDAV </h2>
<table class="tabliste">
<tr><?php
echo "<td>chemin:</td><td>Taille:</td><td>Date modification : </td>";
echo "<td>Type</td>";
echo "<td>name</td>";

echo "</tr>";
$files = $client->propfind('http://192.168.y.z/app/dav/server.php/', array( '{DAV:}getcontentlength',

foreach ($files as $fi => $v)
{
?>
<tr><?php
$fibase = str_replace("/Amnir_Docs_v2/dav/server.php/", "/", $fi);

print_r($fibase);
?>
</td>
<?php
print_r("<td>" . $v['{DAV:}getcontentlength'] . "</td>"); 
print_r("<td>" . $v['{DAV:}getlastmodified'] . "</td>");
print_r("<td>" . $v['{DAV:}resourcetype'] . "</td>"); 
print_r("<td>" . $v['{DAV:}displayname'] . "</td>"); 

echo "</tr>";
?>
</table>
##########################################

Result:
***********************************
chemin:Taille:Date modification :Type: Name:
/Tue, 23 Apr 2013 10:07:32 GMT
/doc_23avril.txt31Tue, 23 Apr 2013 09:50:45 GMT
/fic2.txt4Mon, 08 Apr 2013 13:42:14 GMT

***********************************
Regards

Evert Pot

unread,
Apr 24, 2013, 12:15:01 PM4/24/13
to sabredav...@googlegroups.com

On Apr 24, 2013, at 5:00 PM, ahm...@gmail.com wrote:

>
>
> Le mercredi 24 avril 2013 13:59:18 UTC+1, Evert Pot a écrit :
> On Apr 23, 2013, at 3:08 PM, ahm...@gmail.com wrote:
> Hi,
> Ok, but i have problems with some properties:
>
> resourcetype:
> ##############
>
> Catchable fatal error: Object of class Sabre\DAV\Property\ResourceType could not be converted to string

ResourceType is an object, so you can't just echo it.. Look up that class to see what the object can and cannot do.


>
> ###############
>
> displayname and getcontenttype props are not displayed,

Both are these are optional to implement on the server, so you should not rely on the fact that those exist.


Evert

ahm...@gmail.com

unread,
Apr 25, 2013, 8:06:48 AM4/25/13
to sabredav...@googlegroups.com
Hi,

I think i am going to make it working:

###############################
$res = $v['{DAV:}resourcetype']->getValue();
foreach ($res as $re ) {
if($re == '{DAV:}collection') 
print_r("<td>Folder</td>"); 
else
print_r("<td>File</td>"); 
}
###############################
in the result, i have "Folder" for folders elements but nothing for files,
i chearched in the documentation but all i found is getValue method that returned me an array,
can you help me to do this by appropriated way? 

Regards

Evert Pot

unread,
Apr 25, 2013, 8:08:18 AM4/25/13
to sabredav...@googlegroups.com

On Apr 25, 2013, at 1:06 PM, ahm...@gmail.com wrote:

> Hi,
>
> I think i am going to make it working:
>
> ###############################
> $res = $v['{DAV:}resourcetype']->getValue();
> foreach ($res as $re ) {
> if($re == '{DAV:}collection')
> print_r("<td>Folder</td>");
> else
> print_r("<td>File</td>");
> }
> ###############################
> in the result, i have "Folder" for folders elements but nothing for files,
> i chearched in the documentation but all i found is getValue method that returned me an array,
> can you help me to do this by appropriated way?

The easiest is to use

->is('{DAV:}collection')

this will return true or false.

Evert

ahm...@gmail.com

unread,
Apr 25, 2013, 8:23:22 AM4/25/13
to sabredav...@googlegroups.com
Thnx very much Evert. 
Reply all
Reply to author
Forward
0 new messages