- 📄 Get file list
- 📏 Get file size
- 📥 Download files
- 📤 Upload files
- ❌ Delete files
- PHP 8.0+
- Swoole 5.1.0+
You can install NyaDAV via Composer:
composer require mxmilu666/nyadav
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;
Local download:
$fileInfo = $dav->getfile('/remote.php/webdav/test.txt', 'local_test.txt');
$dav->close();
print_r($fileInfo);
Cloud download (302):
$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();
}
Feel free to contribute by opening issues or submitting pull requests. We welcome all contributions! 🌟
This project is licensed under the Apache-2.0
License.