3 // !!!! Make sure the Sabre directory is in the include_path !!!
5 // set_include_path('lib/' . PATH_SEPARATOR . get_include_path());
9 This example demonstrates a simple way to create your own virtual filesystems.
10 By extending the _File and Directory classes, you can easily create a tree
11 based on various datasources.
13 The most obvious example is the filesystem itself. A more complete and documented
14 example can be found in:
16 lib/Sabre/DAV/FS/Node.php
17 lib/Sabre/DAV/FS/Directory.php
18 lib/Sabre/DAV/FS/File.php
23 date_default_timezone_set('Canada/Eastern');
24 $publicDir = 'public';
27 require_once 'Sabre/autoload.php';
29 class MyDirectory extends Sabre_DAV_Directory {
33 function __construct($myPath) {
35 $this->myPath = $myPath;
39 function getChildren() {
42 // Loop through the directory, and create objects for each node
43 foreach(scandir($this->myPath) as $node) {
45 // Ignoring files staring with .
46 if ($node[0]==='.') continue;
48 $children[] = $this->getChild($node);
56 function getChild($name) {
58 $path = $this->myPath . '/' . $name;
60 // We have to throw a NotFound exception if the file didn't exist
61 if (!file_exists($this->myPath)) throw new Sabre_DAV_Exception_NotFound('The file with name: ' . $name . ' could not be found');
62 // Some added security
64 if ($name[0]=='.') throw new Sabre_DAV_Exception_NotFound('Access denied');
68 return new MyDirectory($name);
72 return new MyFile($path);
80 return basename($this->myPath);
86 class MyFile extends Sabre_DAV_File {
90 function __construct($myPath) {
92 $this->myPath = $myPath;
98 return basename($this->myPath);
104 return fopen($this->myPath,'r');
110 return filesize($this->myPath);
116 // Make sure there is a directory in your current directory named 'public'. We will be exposing that directory to WebDAV
117 $rootNode = new MyDirectory($publicDir);
119 // The rootNode needs to be passed to the server object.
120 $server = new Sabre_DAV_Server($rootNode);