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


In between creating this object and handling the request, you can add any number of plug-ins to the server. The plug-ins perform a variety of functions, such as handling file-locking or doing some other intermediary operations on files.

SabreDAV comes with a number of plug-ins, including:

  • A driver that lets you browse the WebDAV file server through your web browser
  • A driver for file locking (we'll look at this in the next section)
  • A driver to ignore resource fork files (such as the Thumbs.db file in Windows or the .DS_Store and "dot underscore" files in Mac OS X.

All plug-ins extend from the Sabre_DAV_ServerPlugin class. Once instantiated, you add them to the server using the addPlugin() method.

Adding a Web Browser Plug-In

To demonstrate this, let's add the web browser plug-in so we can look at the files on the server through our web browser. The that adds this functionality is Sabre_DAV_Browser_Plugin.

Note: When we implement authentication on our WebDAV server, this will automatically carry over to viewing through your web browser too. Therefore you don't need to worry about this making your server any more insecure.

The following listing shows the code for the WebDAV server, now with the web browser plug-in.

Listing 5 Adding the web browser plug-in to the WebDAV server (listing-5.php)
    $path = '/var/www/dav/files';
    $tree = new Sabre_DAV_ObjectTree(
        new Sabre_DAV_FS_Directory($path)
    $server = new Sabre_DAV_Server($tree);
        new Sabre_DAV_Browser_Plugin()

Now you can try visiting the WebDAV server in your browser. This plug-in lists all files, as well as giving you options for creating folders and uploading files.

Figure 2 Viewing the WebDAV server in a web browser
Figure 2: Viewing the WebDAV server in a web browser

If you would like to apply your own styling to this web-based interface, you can copy the Sabre_DAV_Browser_Plugin to your own plug-in and make any changes to the display as required.

In This Article