How to Install The PHP WebDAV Extension on Debian Squeeze

The PHP WebDAV extension enables users to access remote resources through WebDAV from PHP scripts without any difficulty. It is a quick and user-friendly C wrapper as compared to Neon library.

In this article, we have used a Debian Squeeze server. Make sure to install Apache2 and PHP5 on your system.

Instructions

  • 1

    Installing The PHP WebDAV Extension

    You need to install some dependencies before installing the PHP WebDAV extension. The procedure is given below;

    apt-get install php5-dev build-essential libneon27 libneon27-dev

    Afterwards, you have to download and unpack the PHP WebDAV extension;

    cd /tmp
    wget http://download.pureftpd.org/php-webdav/php-webdav-1.2.tar.gz
    tar xvfz php-webdav-1.2.tar.gz

    Now, alter to the dav directory…

    cd dav/

    After that create the PHP WebDAV extension;

    phpize
    ./configure --enable-dav
    make install

    To allow the extension, make the file /etc/php5/conf.d/dav.ini…

    vi /etc/php5/conf.d/dav.ini

    extension=dav.so

    Now, restart Apache:

    /etc/init.d/apache2 restart

  • 2

    Using The PHP WebDAV Extension

    The below script describes the procedure of using the PHP WebDAV extension;


    That example is quite easy to understand, and it also includes a README file in the PHP WebDAV source package that you have downloaded and has a full function reference;

    .:. PHP WebDAV extension .:.

    ------------------------ BLURB ------------------------

    The PHP WebDAV extension allows easy access to remote resources through the
    DAV protocol.

    It is based upon the Neon reference library.

    The PHP WebDAV extension home page is http://php-webdav.pureftpd.org

    Please report bugs and suggestions to j pureftpd org

    ------------------------ INSTALLATION ------------------------

    This extension requires the Neon library and the related header wp-content/uploads.

    Neon can be downloaded from: http://www.webdav.org/neon/

    Pre-built packages and ports are already available for most operating systems
    and distributions.

    In order to compile and install the PHP WebDAV extension, just follow the
    standard PECL procedure :

    $ phpize
    $ ./configure --enable-dav
    # make install

    On OpenBSD systems, use
    $ env AUTOCONF_VERSION=2.61 phpize

    (replace 2.61 with any of the currently installed versions of autoconf on your
    system)

    ------------------------ BASIC EXAMPLE ------------------------

    webdav_connect('http://webdav.example.com/dav', 'davuser', 'davpassword');
    $a = webdav_get('/my/nice/object.txt');
    webdav_put('/your/nice/thing.txt', $data);
    webdav_unlink('/unwanted_resource.txt');
    webdav_rename('/dir/old_name', '/dir/new_name');
    webdav_copy('/dir/orig_dir', '/dir/new_dir', TRUE);
    webdav_close();

    ------------------------ NAMED RESOURCE EXAMPLE ------------------------

    $res = webdav_connect('http://webdav.example.com/dav', 'davuser', 'davpassword');
    $a = webdav_get('/my/nice/object.txt', $res);
    webdav_put('/your/nice/thing.txt', $data, $res);
    webdav_unlink('/unwanted_resource.txt', $res);
    webdav_rename('/dir/old_name', '/dir/new_name', $res);
    webdav_copy('/dir/orig_dir', '/dir/new_dir', TRUE, $res);
    webdav_close($res);

    ------------------------ ESTABLISHING A CONNECTION ------------------------

    In order to establish a new connection, use:

    webdav_connect(string base_url [, string user [, string password
    [, int timeout]]]

    Examples:

    webdav_connect('http://webdav.example.org/dav/')
    webdav_connect('http://webdav.example.org/dav/', 'myuser', 'mypassword')
    webdav_connect('http://webdav.example.org/dav/', 'myuser', 'mypassword', 10)

    Closing a session just requires a call to webdav_close() :

    webdav_close()
    webdav_close($resource)

    The base url is a string that will be concatened to URI parts of other
    functions in order to get the full resource URL.

    Examples:

    webdav_connect('http://webdav.example.org/dav/');
    $a = webdav_get('nice/object.txt');

    => fetch http://webdav.example.org/dav/nice/object.txt

    webdav_connect('http://webdav.example.org/dav');
    $a = webdav_get('/nice/object.txt');

    => also fetch http://webdav.example.org/dav/nice/object.txt

    webdav_connect('http://webdav.example.org/dav');
    $a = webdav_get('nice/object.txt');

    => WRONG : fetches http://webdav.example.org/davnice/object.txt

    webdav_connect('http://webdav.example.org/dav/');
    $a = webdav_get('/nice/object.txt');

    => WRONG : fetches http://webdav.example.org/dav//nice/object.txt

    As an alternative, the name webdav_open() can be used in place of
    webdav_connect().

    ------------------------ FETCHING A RESOURCE ------------------------

    In order to fetch a resource, use:
    webdav_get(string uri [, resource session])

    The function returns the content, or FALSE if an error occurred.

    ------------------------ STORING A RESOURCE ------------------------

    Storing a resource is available through the webdav_put() function:
    webdav_put(string uri, string data [, resource session])

    ------------------------ DELETING A RESOURCE ------------------------

    webdav_delete() deletes a resource :
    webdav_delete(string uri [, resource session])

    As an alternative, the names webdav_unlink(), webdav_remove() and
    webdav_rmdir() can be used in place of webdav_delete().

    ------------------------ CREATING A COLLECTION ------------------------

    A collection (think about it as a subdirectory if you aren't familiar with
    DAV) is created with the webdav_mkcol() function :

    bool webdav_mkcol(string uri [, resource session])

    As an alternative, the name webdav_mkdir() can be used in place of
    webdav_mkcol().

    ------------------------ COPYING A RESOURCE ------------------------

    If the server implements it, resources can be copied:

    webdav_copy(string source_uri, string target_uri
    [, bool overwrite [, bool recursive [, resource session]]])

    By default, resources can be overwritten and they are recursively copied.

    ------------------------ MOVING/RENAMING A RESOURCE ------------------------

    Resources can also be moved or renamed:

    webdav_move(string source_uri, string target_uri
    [, bool overwrite, [, resource session]])

    As an alternative, the name webdav_rename() can be used in place of
    webdav_move().

    ------------------------------ PHP STREAM API ------------------------------

    As an alternative to webdav_*() functions, the dav_stream.inc.php file can be
    included in your projects so that DAV servers can be reached through standard
    PHP calls, through webdav:// streams:



    require 'dav_stream.inc.php';

    $fp = fopen('webdav://dav.example.com/dav/dir/file.txt', 'w');
    fwrite($fp, "test\n");
    fclose($fp);
    $data = file_get_contents('webdav://dav.example.com/dav/dir/file.txt');
    $st = stat('webdav://dav.example.com/dav/dir/file.txt');
    copy('/tmp/xyz.txt', 'webdav://dav.example.com/dav/dir/xyz.txt');
    unlink('webdav://dav.example.com/dav/dir/abc.txt');

    ?>

    This is a bit slower than native webdav_*() functions.

Leave a Reply

Your email address will not be published. Required fields are marked *


+ seven = 10