mxmilu666/nyadav

PHP 和 Swoole 的简单 WebDAV 客户端

v1.7 2024-08-11 05:32 UTC

This package is auto-updated.

Last update: 2024-09-17 12:18:23 UTC


README

NyaDAV

🐱 NyaDAV

✨ PHP 和 Swoole 的简单 WebDAV 客户端 ✨

功能

  • 📄 获取文件列表
  • 📏 获取文件大小
  • 📥 下载文件
  • 📤 上传文件
  • ❌ 删除文件

要求

  • PHP 8.0+
  • Swoole 5.1.0+

安装

您可以通过 Composer 安装 NyaDAV

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;

下载文件

本地下载

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

云下载(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();
}

贡献

请随意通过开启问题或提交拉取请求进行贡献。我们欢迎所有贡献! 🌟

许可证

本项目采用 Apache-2.0 许可证。