PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Implementing a WebDAV filesystem with PHP and SabreDAV

Ignoring Temporary Files

Both Windows and OS X write temporary/hidden files used to store additional information about files (such as a thumbnails of photos, or in which direction files should be displayed in a folder).

While these can be useful when browsing files on the operating system, they can cause a bit of clutter.

SabreDAV comes with a plug-in you can easily add that will hide these files. It writes them to a temporary directory rather than your WebDAV files directory.

The name of this plug-in is Sabre_DAV_TemporaryFileFilterPlugin. You can pass the path where temporary files should be stored as the its only argument, or you can leave this blank and it will use the system temporary directory.

Caution: SabreDAV will not automatically clean up this directory. You should manually clear this write a cron job that will do so for you.

The following list shows how you can use this plug-in. Just like with any other plug-in it is added using the addPlugin() method.

Listing 6 Automatically filtering resource forks with built-in plug-in (listing-6.php)
<?php
    require_once('Sabre.autoload.php');
 
    $path = '/var/www/dav/files';
 
    $tree = new Sabre_DAV_ObjectTree(
        new Sabre_DAV_FS_Directory($path)
    );
 
    $server = new Sabre_DAV_Server($tree);
 
    $server->addPlugin(
        new Sabre_DAV_TemporaryFileFilterPlugin()
    );
 
    $server->exec();
?>

In This Article