All Projects → jedisct1 → PHP-WebDAV-extension

jedisct1 / PHP-WebDAV-extension

Licence: ISC license
The PHP WebDAV extension allows easy access to remote resources with PHP through the DAV protocol.

Programming Languages

shell
77523 projects
c
50402 projects - #5 most used programming language
PHP
23972 projects - #3 most used programming language
awk
318 projects
C++
36643 projects - #6 most used programming language
M4
1887 projects
                         .:. 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 <at> pureftpd <dot> org


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

This extension requires the Neon library and the related header files.

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:

<?php

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].