phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Failure of download file from sharepoint

Open joannelfm opened this issue 3 years ago • 2 comments

I installed phpSPO library in Windows server and want to download a file from Sharepoint Documents folder, which needs credential to login. I use user credentials auth to get the file, but it shows the error.

============ Fatal error: Uncaught Error: Class 'AuthenticationContext' not found in C:\xxx\xxx\xxx\xxx\DownloadFile.php:16 Stack trace: #0 {main} thrown in C:\xxx\xxx\xxx\xxx\DownloadFile.php on line 16

Codes in DownloadFile.php

acquireTokenForUser($username,$password); $ctx = new ClientContext($url,$authCtx); $fileUrl = 'https://test.sharepoint.com/sites/test/'; $sourceLibraryTitle = "Documents"; $sourceList = $ctx->getWeb()->getLists()->getByTitle($sourceLibraryTitle); //$files = $sourceList->getRootFolder()->getFiles(); $files = array("fileabc.xlsx"); $ctx->load($files); $ctx->executeQuery(); /** @var File $file */ foreach ($files->getData() as $file){ try { $temp_file = join(DIRECTORY_SEPARATOR,[sys_get_temp_dir(),$file->getName()]); $result = $file->download(); $ctx->executeQuery(); file_put_contents($targetFilePath, $result->getValue()); print "File {$file->getServerRelativeUrl()} has been downloaded successfully\r\n"; } catch (Exception $e) { print "File download failed:\r\n"; } } Please help for this. Thanks

joannelfm avatar Jul 24 '20 01:07 joannelfm

Hello

Sound a little that you are just missing something on top of the file.

Do you have these lines?

hnpilot avatar Aug 05 '20 12:08 hnpilot

Hello,

2.3.1 to 2.4 changed namespace.

From:

namespace Office365\PHP\Client\Runtime\Auth;

To:

namespace Office365\Runtime\Auth;

Is that maybe the cause of your errors?

fdverwoerd avatar Aug 27 '20 08:08 fdverwoerd