#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    PHP DAV library (SabreDAV) for setting up a WebDAV client


    Hi everyone,

    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 :
    ----/en/php_library
    And the scripts here :
    ----/en/php_script


    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.

    3. Installation

    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.

    4. Example

    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.

    include 'Sabre/autoload.php';

    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":

    $dav->request('MKCOL', '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:

    $dav->request('DELETE', 'test/test.txt');

    You can also delete a directory using the same method:

    $dav->request('DELETE', 'test/');
    Last edited by E-Oreo; December 14th, 2012 at 08:34 PM.
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,997
    Rep Power
    9397
    Originally Posted by E-Oreo
    I can see where the WebDAV part might be frequently asked, but the [company] part just looks like an advertisement to me.

    My $0.02; I will remove that from the OP unless others disagree with that assessment. Particularly because http://[domain.com] doesn't even resolve for me.
    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.
    I'm also kinda hoping other people see this thread and contribute to it.
    Last edited by requinix; December 14th, 2012 at 02:46 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Hello,

    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)

IMN logo majestic logo threadwatch logo seochat tools logo