88use Office365 \SharePoint \ClientContext ;
99
1010
11- function uploadFileAlt (ClientContext $ ctx , $ sourceFilePath , $ targetFileUrl )
11+ /* function uploadFileAlt(ClientContext $ctx, $sourceFilePath, $targetFileUrl)
1212{
1313 $fileContent = file_get_contents($sourceFilePath);
1414 try {
@@ -17,25 +17,19 @@ function uploadFileAlt(ClientContext $ctx, $sourceFilePath, $targetFileUrl)
1717 } catch (Exception $e) {
1818 print "File upload failed:\r\n";
1919 }
20- }
21-
20+ }*/
2221
23- try {
24- $ credentials = new UserCredentials ($ settings ['UserName ' ], $ settings ['Password ' ]);
25- $ ctx = (new ClientContext ($ settings ['Url ' ]))->withCredentials ($ credentials );
26- $ localPath = "../data/ " ;
27- $ targetLibraryTitle = "Documents " ;
28- $ targetList = $ ctx ->getWeb ()->getLists ()->getByTitle ($ targetLibraryTitle );
2922
30- $ searchPrefix = $ localPath . '*.* ' ;
31- foreach (glob ($ searchPrefix ) as $ filename ) {
32- $ uploadFile = $ targetList ->getRootFolder ()->uploadFile (basename ($ filename ),file_get_contents ($ filename ));
33- $ ctx ->executeQuery ();
34- print "File {$ uploadFile ->getServerRelativeUrl ()} has been uploaded \r\n" ;
35- }
23+ $ credentials = new UserCredentials ($ settings ['UserName ' ], $ settings ['Password ' ]);
24+ $ ctx = (new ClientContext ($ settings ['Url ' ]))->withCredentials ($ credentials );
25+ $ localPath = "../../data/ " ;
26+ $ targetLibraryTitle = "Documents " ;
27+ $ targetList = $ ctx ->getWeb ()->getLists ()->getByTitle ($ targetLibraryTitle );
3628
37- }
38- catch (Exception $ e ) {
39- echo 'Error: ' , $ e ->getMessage (), "\n" ;
29+ $ searchPrefix = $ localPath . '*.* ' ;
30+ foreach (glob ($ searchPrefix ) as $ filename ) {
31+ $ uploadFile = $ targetList ->getRootFolder ()->uploadFile (basename ($ filename ),file_get_contents ($ filename ));
32+ $ ctx ->executeQuery ();
33+ print "File {$ uploadFile ->getServerRelativeUrl ()} has been uploaded \r\n" ;
4034}
4135
0 commit comments