Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP访问WebDAV_Php_Webdav_Nextcloud - Fatal编程技术网

使用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);