PHP PEAR WebDAV Server




This package looks terrific. I tried it once years ago, and am now trying again.

pear install HTTP_WebDAV_Server
vim /usr/share/php/docs/HTTP_WebDAV_Server/db/Fileserver.sql

I installed the database, and then tried the simple script offered here:

How to install a webdav server in php

Since I run PHP as a CGI script, I had to add this snibbet I found at the php.net website:

if (!function_exists('apache_request_headers')) {
    eval('
        function apache_request_headers() {
            foreach($_SERVER as $key=>$value) {
                if (substr($key,0,5)=="HTTP_") {
                    $key=str_replace(" ","-",ucwords(strtolower(str_replace("_"," ",substr($key,5)))));
                    $out[$key]=$value;
                }
            }
            return $out;
        }
    ');
}

Reading through the docs again, the Server/Filesystem.php file is just an example of how the Server.php class can be extended. I copied this file to my working directory, started to make a few changes, and some cool ideas came to mind:
* use MDB2 for file locking instead of only mysql
* combine with jquery.fileTree for user-friendly navigation
* combine with pecl svn php extension for versioning support

There are many opportunities for coolness here. I’m going to get started on something boring yet important: file uploads. To do this I’m actually going to use the HTTP_WebDAV_Client package from PEAR as well. It simply registers the webdav: and webdavs: protocols so you can do stuff like this:

$httpfile  = file_get_contents("webdav://www.example.com/foo.txt");

3 Responses to “PHP PEAR WebDAV Server”


  1. 1 adam

    Since you seem to have had some success with this wrapper I was hoping maybe you could help me out by posting an example or at least some suggestions. What I am trying to do is upload a video from the server my website is hosted on to a remote server with webdav. My local server has WinNT, php 4.3 and apache 2.0. currently I am doing something along the lines of:

    $strm = new HTTP_WebDAV_Client_Stream;
    $tmp_vid_loc = $_FILES[’newVid’][’tmp_name’];
    $target_vid_path = ‘webdav://user:pass@stream.address.com/WMRoot/ce/’ . $full_tid . ‘.wvx’;

    $opts = array();
    $opened = array();
    $strm->stream_open($target_vid_path, ‘w’, $opts, $opened);

    $src = fopen($tmp_vid_loc, ‘rb’);
    $content = fread($src, filesize( $tmp_vid_loc));
    fclose($src);

    $strm->stream_write($content);
    $strm->stream_close();

    I get no errors from this but I have checked and found that both stream_open and stream_write are returning false. Upon further investigation I have found that stream_write is failing because of something to do with the options parameter. I find this especially confusing because the (very) limited documentation only says this parameter is “not used here” which is why I pass an empty array.

    Thanks in advance for any help. Also if there is any other info I can provide I am more than happy to.

  2. 2 Albert

    Hi Adam, I’m more familiar with the dav server than the client. And I think that there is a webdav extension which I found to have helpful documentation:

    http://php-webdav.pureftpd.org/project/php-webdav

    But back to your situation, a stream wrapper should work the same way the rest of php streams work. Here’s a few examples:

    http://www.php.net/manual/en/stream.examples.php

    So if you register the webdav wrapper as “webdav”, you should then be able to simple copy the uploaded file to your webdav server, like with file_put_contents, for example:

    http://www.php.net/manual/en/function.file-put-contents.php

    Hope that helps! Let me know if that helps, if not, I can try again. :-)

  3. 3 Marc

    Hey Albert,
    although Adam seems to be busy, I tried your suggestion because I was wondering why the HTTP_WebDAV_Client_Stream Class seems to be so ‘unhandy’ - and yes! it works!
    Just register with the webdav protocal with HTTP_WebDAV_Client_Stream::register()
    and you can use the file_* functions with your webdav server!

    Thank you so much! :-)
    Best regards,
    Marc

Leave a Reply