From 56b3ae4cccd531c7267849ef6d1f13db3a7ffaab Mon Sep 17 00:00:00 2001 From: Jarrod Swift Date: Fri, 7 Jan 2022 15:42:19 +1030 Subject: [PATCH] Added creating files via webdav (Issue #98) --- src/BigCommerce/Files/BigCommerceFilesClient.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/BigCommerce/Files/BigCommerceFilesClient.php b/src/BigCommerce/Files/BigCommerceFilesClient.php index b90a6f75..f7c04b14 100644 --- a/src/BigCommerce/Files/BigCommerceFilesClient.php +++ b/src/BigCommerce/Files/BigCommerceFilesClient.php @@ -50,7 +50,8 @@ private function buildDefaultHttpClient(): \GuzzleHttp\Client self::DEFAULT_HANDLER => $stack, self::DEFAULT_BASE_URI => $this->webdavPath, 'auth' => [$this->webdavUsername, $this->webdavPassword, 'digest'], - 'http_errors' => false + 'http_errors' => false, + 'version' => 1.1, ]); } @@ -72,8 +73,17 @@ public function get(string $filename): ?string } } - public function put() + public function put(string $localFilename, string $targetFilename): bool { + $file = fopen($localFilename, 'r'); + if (!$file) return false; + + $response = $this->client->put($targetFilename, + [ + 'body' => $file + ]); + + return $response->getStatusCode() === 201; } }