Jyxo\Webdav\Client::copy PHP Méthode

copy() public méthode

Does not work on Lighttpd.
public copy ( string $pathFrom, string $pathTo )
$pathFrom string Source file path
$pathTo string Target file path
    public function copy(string $pathFrom, string $pathTo)
    {
        $pathTo = $this->getFilePath($pathTo);
        // Try creating the directory first
        if ($this->createDirectoriesAutomatically) {
            try {
                $this->mkdir(dirname($pathTo));
            } catch (DirectoryNotCreatedException $e) {
                throw new FileNotCopiedException(sprintf('File %s cannot be copied to %s.', $pathFrom, $pathTo), 0, $e);
            }
        }
        $requests = [];
        foreach ($this->servers as $server) {
            $requests[$server] = $this->createRequest($server, $this->getFilePath($pathFrom), self::METHOD_COPY, ['Destination' => $server . $pathTo]);
        }
        foreach ($this->sendAllRequests($requests) as $response) {
            // 201 means copied
            if (self::STATUS_201_CREATED !== $response->getStatusCode()) {
                throw new FileNotCopiedException(sprintf('File %s cannot be copied to %s.', $pathFrom, $pathTo));
            }
        }
    }

Usage Example

Exemple #1
0
 /**
  * Tests file copying.
  *
  * @depends testPut
  */
 public function testCopy()
 {
     // Lighttpd does not support this method.
     // $this->assertTrue($this->client->copy($this->file, $this->dir . '/testcopy.txt'));
     $this->assertFalse($this->client->copy($this->dir . '/dummy.txt', $this->dir . '/dummycopy.txt'));
 }