December 14th, 2012, 11:22 AM
PHP DAV library (SabreDAV) for setting up a WebDAV client
I would like to present you the SabreDAV library which is a PHP library that provides access to online file storage.
I represent the online storage ----. There is an unlimited storage and is working with the protocol WebDAV. I would like to know your opinion on working the library on this online storage. Nothing more.
You can find the full tutorial here :
And the scripts here :
2. Latest version
Latest version v1.5.2 (released 2011-09-21)
Download available at: code.google.com/p/sabredav/
This version is supported by Unix and Windows and operates under Apache 2.
To use SabreDAV, you will need a recent version of PHP5, as well as the DOM and SimpleXML extensions. In most cases, this is installed by default.
You can install SabreDAV via PEAR (a collection of PHP libraries) or manually.
Installation via PEAR :
If you have not already installed PEAR, you can find installation instructions here: pear.php.net/manual/en/installation.getting.php
Once PEAR is installed and running, install SabreDAV with the following command:
pear channel-discover pear.sabredav.org pear install sabredav / Sabre_DAV
If you want to also install CalDAV, just add:
pear channel-discover pear.sabredav.org pear install sabredav / Sabre_CalDAV
Manual installation :
You can also download the latest package manually HERE. The program is distributed as a zip archive and contains all the files needed for SabreDAV to operate properly.
After extracting the files, a Sabre_DAV-xxx directory will be created with all of the required files (all scripts in the library will be found in the lib/ directory). To use SabreDAV, just include lib/Sabre/autoload.php in your PHP script.
This example is based on the introduction to using SabreDAV with the WebDAVClient available HERE.
We will create the testdav.php file, a script in PHP that we will execute using the command line: phptestdav.php
As with any PHP script, we need to define the open and close tags around the PHP code we wish to create.
We will now import the SabreDAV library to make the necessary calls to interact with the WebDAV server.
Now we will define the URL to connect to ---- (for example, for the user "pcollins") then the authentication information needed to access a protected resource.
$settings = array( 'baseUri' => 'domain.com/', 'userName' => 'pcollins', 'password' => 'mypass' );
Now we will create a new DAV client for the URL previously defined (HTTPS protocol):
$dav = new Sabre_DAV_Client($settings);
We can now start by creating the root / of a new directory called "test":
Let's continue with uploading a file to ---- in the "/test" directory. To upload a file, we will open the local file to upload through the fopen() command to get its content, then we will upload the content to the new test.txt file:
$filepath = "test_file.txt"; $fh = fopen($filepath, 'r'); $content = fread($fh, filesize($filepath)); fclose($fh); $dav->request('PUT', 'test/test.txt', $content);
We can now download this "test/test.txt" file and move it to the local location: "/testdav/test_file.txt". Once the content is downloaded, we will save it in the selected file.
$res = $dav->request('GET', 'test/test.txt'); $filepath = "/testdav/test_file.txt"; $fh = fopen($filepath, 'w'); fwrite($fh, $res['body']); fclose($fh);
To delete the file previously created:
You can also delete a directory using the same method:
Last edited by E-Oreo; December 14th, 2012 at 09:34 PM.
December 14th, 2012, 03:43 PM
www.[domain.com] works though. You have a point though - I'm currently interested in WebDAV solutions, like SabreDAV, so I may be a bit biased. Go ahead and edit the post, maybe like "if you need to connect to a remote service" and like "if you need a username/password". Or just flat out remove it since I think it's fairly uncommon.
Originally Posted by E-Oreo
I'm also kinda hoping other people see this thread and contribute to it.
Last edited by requinix; December 14th, 2012 at 03:46 PM.
December 17th, 2012, 03:36 AM
I certainly represent a commercial solution (iKeepinCloud) but I don't want make the advertisement here. I'am trying to gather some advice about the use of the Sabredav library on this webDav Client.
This client is an online storage and there is absolutely no online storage solution working with WebDAV. (Or I did not find some)