> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://wiki.leviia.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Using the Leviia Drive API - PHP

###### Installing PHP and its dependencies :

To install PHP on your environment, go to: https://www.php.net/manual/fr/install.php. 

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

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

Click here for SabreDAV documentation : https://sabre.io/dav/install/. 

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

###### Client creation :

To initialize login information :

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

$settings = array(
    'baseUri' => 'https://cloud.leviia.com/',
    '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 :

```php
$response = $client->propfind($base."/", array(
    '{DAV:}displayname',
    '{DAV:}getcontentlength',
),1);

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

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

```php
$response = $client->propfind($base."/documents/", array(
    '{DAV:}displayname',
    '{DAV:}getcontentlength',
),1);

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

###### Send a file to Leviia :

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

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

###### Download a file from Leviia :

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

###### Create a folder on Leviia :

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

###### Delete a folder/file on Leviia :

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