Last active
December 16, 2022 02:07
-
-
Save mannysoft/cbb32acff7efaf930abbc1e7a5ebd26c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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