PHP code example of mxmilu666 / nyadav

1. Go to this page and download the library: Download mxmilu666/nyadav library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mxmilu666 / nyadav example snippets


use NyaDAV\NyaDAV;
use NyaDAV\NyaDAVException;

try {
    $dav = new NyaDAV('example.com', 80, false); // Set true for SSL
} catch (NyaDAVException $e) {
    echo $dav->err;
    //or
    echo 'Error: ' . $e->getMessage();
}

$dav->set([
    'auth' => [
        'username' => 'your-username',
        'password' => 'your-password'
    ],
    'depth' => 1
]);

try {
    $files = $dav->getfilelist('/remote.php/webdav/');
    $dav->close();
    print_r($files);
} catch (NyaDAVException $e) {
    echo $dav->err;
    //or
    echo 'Error: ' . $e->getMessage();
}


$size = $dav->getfilesize('/remote.php/webdav/test.txt');
$dav->close();
echo 'File Size: ' . $size;


$fileInfo = $dav->getfile('/remote.php/webdav/test.txt', 'local_test.txt');
$dav->close();
print_r($fileInfo);


$fileInfo = $dav->getfile('/remote.php/webdav/test.txt');
$dav->close();
print_r($fileInfo);


try {
    $success = $dav->uploadfile('/remote.php/webdav/uploaded.txt', 'local_upload.txt');
    $dav->close();
    if ($success) {
        echo 'File uploaded successfully!';
    }
} catch (NyaDAVException $e) {
    echo $dav->err;
    //or
    echo 'Error: ' . $e->getMessage();
}


try {
    $success = $dav->deletefile('/remote.php/webdav/uploaded.txt');
    $dav->close();
    if ($success) {
        echo 'File deleted successfully!';
    }
} catch (NyaDAVException $e) {
    echo $dav->err;
    //or
    echo 'Error: ' . $e->getMessage();
}


try {
    $success = $dav->file_exists('/remote.php/webdav/test.txt');
    $dav->close();
    if ($success) {
        echo 'exists';
    }
    else{
        echo 'not exist';
    }
} catch (NyaDAVException $e) {
    echo $dav->err;
    //or
    echo 'Error: ' . $e->getMessage();
}