@@ -91,6 +91,8 @@ protected function ensureValidPath(string $path)
91
91
92
92
public function write (string $ path , string $ contents , Config $ config ): void
93
93
{
94
+ $ path = trim ($ path , '/ ' );
95
+ $ this ->ensureValidPath ($ path );
94
96
//Files larger than 4MiB require an UploadSession
95
97
if (strlen ($ contents ) > 4194304 ) {
96
98
$ stream = fopen ('php://temp ' , 'r+ ' );
@@ -101,8 +103,6 @@ public function write(string $path, string $contents, Config $config): void
101
103
return ;
102
104
}
103
105
104
- $ path = trim ($ path , '/ ' );
105
- $ this ->ensureValidPath ($ path );
106
106
107
107
$ file_name = basename ($ path );
108
108
$ parentItem = $ this ->getUrlToPath (dirname ($ path ));
@@ -268,14 +268,12 @@ public function createDirectory(string $path, Config $config): void
268
268
{
269
269
$ newDirPathArray = explode ('/ ' , $ path );
270
270
$ newDirName = array_pop ($ newDirPathArray );
271
- $ parentItem = count ($ newDirPathArray )
272
- ? $ this ->getUrlToPath (implode ('/ ' , $ newDirPathArray ))
273
- : $ this ->getDriveRootUrl ();
271
+ $ path = implode ('/ ' , $ newDirPathArray );
274
272
275
273
$ dirItem = $ this ->graph
276
274
->createRequest (
277
275
'POST ' ,
278
- $ this ->getDriveItemUrl ( $ parentItem ) . '/children '
276
+ $ this ->getUrlToPath ( $ path ) . ': /children '
279
277
)
280
278
->attachBody ([
281
279
'name ' => $ newDirName ,
@@ -469,13 +467,8 @@ private function getFileAttributes(string $path): FileAttributes
469
467
470
468
protected function ensureDirectoryExists (string $ path )
471
469
{
472
- $ directories = explode ('/ ' , $ path );
473
- $ current_path = '' ;
474
- foreach ($ directories as $ directory ) {
475
- $ current_path = trim ($ current_path .= '/ ' . $ directory , '/ ' );
476
- if (!$ this ->directoryExists ($ current_path )) {
477
- $ this ->createDirectory ($ current_path , new Config ());
478
- }
470
+ if (!$ this ->directoryExists ($ path )) {
471
+ $ this ->createDirectory ($ path , new Config ());
479
472
}
480
473
}
481
474
0 commit comments