Implementing a WebDAV filesystem with PHP and SabreDAV
Plug-Ins
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.dbfile in Windows or the.DS_Storeand "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.
The following listing shows the code for the WebDAV server, now with the web browser plug-in.
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_Browser_Plugin() ); $server->exec();
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.
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.




