Articles on: API

Using the Leviia Drive API - PHP

Installing PHP and its dependencies :

To install PHP on your environment, go to:

Once your PHP environment is up and running (hello-world.php is up and running), install php-curl and SabreDAV (WebDAV client for PHP). Here's an example, to be adapted to your environment, under Linux (Debian) :

apt update
apt install php-curl
composer require sabre/dav ~3.2.0

Click here for SabreDAV documentation :

You can now connect your PHP code to your Leviia account.

Client creation :

To initialize login information :

use Sabre\DAV\Client;
include 'vendor/autoload.php';

$settings = array(
    'baseUri' => '',
    'userName' => 'thomas',
    'password' => '*******',

$client = new Client($settings);
$base = "/remote.php/dav/files/$settings[userName]";

List the contents of a directory :

To list the contents of the root directory ("/"), use :

$response = $client->propfind($base."/", array(

echo '<pre>'; print_r($response); echo '</pre>';

To list the contents of a subdirectory, simply replace "/" with the directory path :

$response = $client->propfind($base."/documents/", array(

echo '<pre>'; print_r($response); echo '</pre>';

Send a file to Leviia :

$fh_res = fopen("/CHEMIN/VERS/LE/FICHIER", 'r');

$response = $client->request('PUT', $base.'/FICHIER', $fh_res);

Download a file from Leviia :

$response = $client->request('GET',$base.'/FICHIER/DISTANT');
$file = fopen('/CHEMIN/LOCAL', "w+");
fputs($file, $response["body"]);

Create a folder on Leviia :

$response = $client->request('MKCOL', $base.'/CHEMIN');

Delete a folder/file on Leviia :

$response = $client->request('DELETE', $base.'/CHEMIN');

Updated on: 08/01/2024

Was this article helpful?

Share your feedback


Thank you!