How can I rename a webdav collection using Symfony Client?

214 views Asked by At

I am using an http Client with Symfony. In this example I am creating a folder.

 $client = HttpClient::create();

 /* @var $response ResponseInterface */
 $createFolder = $client->request('MKCOL', $filePath, [
     'auth_basic' => [$user, $authKey],
 ]);

This works well.

Now I want to rename a folder:

 $renameFolder = $client->request('MOVE', $filePath, [
     'auth_basic' => [$user, $authKey],
 ]);

But what I cannot figure out is, where do I define the new folder name?

1

There are 1 answers

3
yivi On BEST ANSWER

You seem to be accessing a Webdav server, from the MKCOL command.

If you want to use MOVE, the destination should be passed on a Destination header, as shown here.

With Symfony Http Client, the request would be something like:

$moveCollection =  $client->request('MOVE', $collectionPath,
    [
     'auth_basic' => [$user, $authKey],
     'headers'    => [
            'Destination' => $newCollectionPath
        ]
    ]
);