I have created a web interface to allow external users to upload files to our sharepoint library using ajax and the phpSPO library. It all works really well, however, I am looking to optimise the upload function alot more.
Currently the all the selected files are sent together in one request to PHP then uploaded one at a time into sharepoint.
I am looking to upload multiple files concurrently.
I know how to set up the client side with ajax and the deferred/promise objects and send individual requests to the server for each file.
The bit I dont know, or even if the phpSPO library can handle it, is to Authenticate at the beginning of the process then use the token with subsequent requests to upload the files into sharepoint.
Does anyone have/know of any code snippets that show how to use the token with a phpSPO request?
EDIT:
Here is my class that initiates the connection to sharepoint:
class SPOInstance
{
public $authCtx;
public $ctx;
public $clientfolder;
public $log;
function __construct()
{
try {
$this->authCtx = new AuthenticationContext(app()->webUrl);
$this->authCtx->acquireTokenForUser(app()->username, app()->password); //authenticate
$this->ctx = new ClientContext(app()->webUrl, $this->authCtx);
$token = $this->authCtx->getAccessToken();
file_put_contents(__DIR__ .'/accesstoken.txt', $token."\r\n", FILE_APPEND);
}
catch(Exception $e) {
echo 'Authentication failed: ', $e->getMessage(), "\n";
p2($e->getTrace());
}
}
The $token variable is empty.
So once I have worked out how to get the token, how do I use that to recreate the ClientContext object for subsequent requests?
Cheers
Greg J