mxmilu666 / nyadav
The simple WebDAV client for PHP and Swoole
v1.7
2024-08-11 05:32 UTC
Requires
- php: ^8.0
- ext-swoole: ^5.1.0
Requires (Dev)
- swoole/ide-helper: ^5.1.0
README
🐱 NyaDAV
✨ The simple WebDAV client for PHP and Swoole ✨
Features
- 📄 Get file list
- 📏 Get file size
- 📥 Download files
- 📤 Upload files
- ❌ Delete files
Requirements
- PHP 8.0+
- Swoole 5.1.0+
Installation
You can install NyaDAV via Composer:
composer require mxmilu666/nyadav
Usage
Initialize the Client
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(); }
Set Client Settings
$dav->set([ 'auth' => [ 'username' => 'your-username', 'password' => 'your-password' ], 'depth' => 1 ]);
Get File List
try { $files = $dav->getfilelist('/remote.php/webdav/'); $dav->close(); print_r($files); } catch (NyaDAVException $e) { echo $dav->err; //or echo 'Error: ' . $e->getMessage(); }
Get File Size
$size = $dav->getfilesize('/remote.php/webdav/test.txt'); $dav->close(); echo 'File Size: ' . $size;
Download File
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);
Upload File
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(); }
Delete File
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(); }
File Exists
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(); }
Contributing
Feel free to contribute by opening issues or submitting pull requests. We welcome all contributions! 🌟
License
This project is licensed under the Apache-2.0
License.