使用PHP访问WebDAV
我有以下代码:使用PHP访问WebDAV,php,webdav,nextcloud,Php,Webdav,Nextcloud,我有以下代码: <?php include 'vendor/autoload.php'; use Sabre\DAV\Client; $settings = array( 'baseUri' => "https://example.com/remote.php/dav/files/foo/", 'userName' => "foo", 'password' => "secret" ); $client = new Client($setting
<?php
include 'vendor/autoload.php';
use Sabre\DAV\Client;
$settings = array(
'baseUri' => "https://example.com/remote.php/dav/files/foo/",
'userName' => "foo",
'password' => "secret"
);
$client = new Client($settings);
$response = $client->request('GET');
var_dump($response);
如果我这样做
<?php
include 'vendor/autoload.php';
use Sabre\DAV\Client;
$settings = array(
'baseUri' => "https://example.com/remote.php/dav/files/foo/",
'userName' => "foo",
'password' => "secret"
);
$client = new Client($settings);
$folder_content = $client->propFind('/', array(
'{DAV:}getlastmodified',
'{DAV:}getcontenttype',
),1);
var_dump($folder_content);
当您调用
$client->propFind('/',..)
时,实际有效的url将是:
https://example.com/
而不是
https://example.com/remote.php/dav/files/foo/
要获取相对于基本uri的文件夹内容,只需删除斜杠
$folder_content = $client->propFind('', array(
'{DAV:}getlastmodified',
'{DAV:}getcontenttype',
),1);
应在
use
语句之前调用自动加载器。此处为倒排:应在use语句之前调用自动加载器
此语句无效。您错了@MarkusZeller@emix请在包含之前解释如何使用未声明的命名空间?方法相同。在继续与我讨论之前,请先阅读名称空间的工作原理。
https://example.com/
https://example.com/remote.php/dav/files/foo/
$folder_content = $client->propFind('', array(
'{DAV:}getlastmodified',
'{DAV:}getcontenttype',
),1);