Skip to content

Instantly share code, notes, and snippets.

@mannysoft
Last active December 16, 2022 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mannysoft/cbb32acff7efaf930abbc1e7a5ebd26c to your computer and use it in GitHub Desktop.
Save mannysoft/cbb32acff7efaf930abbc1e7a5ebd26c to your computer and use it in GitHub Desktop.
<?php
use Office365\Runtime\Auth\UserCredentials;
use Office365\Runtime\Auth\ClientCredential;
use Office365\SharePoint\ClientContext;
use Office365\SharePoint\File;
use Office365\Runtime\Http\RequestException;
$credentials = new ClientCredential('xxxx', 'xxxxxx=');
$ctx = (new ClientContext('https://xxxx.sharepoint.com/sites/backup'))->withCredentials($credentials);
$filename = 'filename.pdf';
$fileUrl = '/sites/backup/Shared Documents/' . basename($filename);
// Check if exists
$file = $ctx->getWeb()->getFileByServerRelativeUrl($fileUrl);
// Upload
$uploadFile = $targetList->getRootFolder()->uploadFile(basename($filename),file_get_contents($filename));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment