I've been working on a small project in which i try to upload a file to a specific SharePoint folder using phpSPO.
<?php
require_once '../vendor/autoload.php';
use Office365\Runtime\Auth\UserCredentials;
use Office365\SharePoint\ClientContext;
$siteUrl = "https://mytennant.sharepoint.com";
$relativeUrl = "/sites/LMS/Sharepoint/10./Test_folder";
$username = "myemail";
$password = "mypassword";
$credentials = new UserCredentials("{$username}", $password);
$client = (new ClientContext("{$siteUrl}{$relativeUrl}"))->withCredentials($credentials);
$file_path = "../files/Example.txt";
$targetFolder = "{$relativeUrl}/Sharepoint/10./Test_folder";
$targetFile = $file_path;
$fileContent = file_get_contents($file_path);
Office365\SharePoint\File::saveBinary($client, $targetFile,$fileContent);
die("Not Working");
?>
This is the code that i have been using, I found it in a thread after failing to get the example file upload script provided in the documentation working. I expected this to upload the file example.txt to the SharePoint folder 10./test_folder but whenever I load the php file it gives me this error:
Fatal error: Uncaught Office365\Runtime\Http\RequestException in C:\xampp\htdocs\LMSFileupload\vendor\vgrem\php-spo\src\Runtime\Http\Requests.php:34 .... #6 {main} thrown in C:\xampp\htdocs\LMSFileupload\vendor\vgrem\php-spo\src\Runtime\Http\Requests.php on line 34
I'm not too sure where to start looking to fix this problem because i am quite inexperienced with phpSPO and php in general.
I have tried altering conditional access policies, changing file and folder names, as well as uploading different types of files expecting them to get uploaded to the folder but none of them do.