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

Virtual Filesystems

So far in this article we've implemented a fully-working WebDAV server using SabreDAV's built-in file system tree. If your files are stored in a different manner, this can also be used with SabreDAV.

For example, you might use a database to store information about files in addition to storing them on disk. If you were doing this then you would want to make necessary database updates when a file is created, edited, moved or deleted.

We're not going to implement a custom filesystem in this article, but hopefully the following paragraphs provide a starting for implementing your own.

To implement such a solution you must extend the Sabre_DAV_Tree class. The only method you need to implement to do this is the getNodeForPath() method.

This method resolves a file path to a PHP object that SabreDAV can use. The object returned must implement the Sabre_DAV_IDirectory interface if it is a directory, or it must implement Sabre_DAV_IFile if it is a file.

These interfaces define a number of methods in regards to handling WebDAV operations. For instance, your class that implements Sabre_DAV_IDirectory must define how to create, remove and delete a directory.

To get a better idea of how this fits together, I recommend looking at the following classes:

  • Sabre_DAV_FS_Directory
  • Sabre_DAV_FS_File

Objects of these types are returned from the getNodeForPath() method in Sabre_DAV_ObjectTree method.

In effect, you can duplicate these classes and add in your own database methods where applicable.

In This Article