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

Introduction

In this article I will show you how to create a WebDAV filesystem using PHP and the open-source library SabreDAV. We are going to create a simple web drive that stores its files in a directory on the web server. By the end you will be able to effectively map this directory to your local computer and update files using your native operating system.

Put simply, WebDAV (Web-based Distributed Authoring and Versioning) is an extension of HTTP that allows you to manage files on a remote web server. It allows you to think of files and directories on a web site as though they are local files on your computer.

Modern operating systems (such as Microsoft Windows or Mac OS X) provide native functionality for mapping a "web drive" as a local drive. This means you can easily open, edit, move and delete files on a web site as though they are files on your computer.

Figure 1 Mapping a WebDAV drive in Mac OS X
Figure 1: Mapping a WebDAV drive in Mac OS X

In this article I'm not going to describe specifically how WebDAV works (it's just a series of HTTP requests). Rather, I'm going to show you how you can implement a solution for your own web site.

This type of functionality can be extremely useful in web applications such as Content Management Systems. For example, my company develops a Content Management System (Recite CMS), which allow users to parts of their web site to their local drive.

In Recite CMS, users can upload new files to their web site just by dragging them to the mapped drive. Alternatively, they can make changes to their web site's CSS files and templates using their favourite text editor.

When implementing a WebDAV solution, you must be aware that the different client platforms (be it Windows, OS X or otherwise) all behave slightly differently. This article includes of what to be aware of, and by the end of this article we'll have a system that works well on most (if not all) platforms.

This article assumes you have a Unix-based Apache web server and that you can create a new virtual host on it to act as your WebDAV server.

In This Article