4

I saw from one of your previous post that you are an author of phpSPO. I came across your phpSPO library earlier this month while trying to access sharepoint by php.

I went through your GitHub and saw the samples but with my limited knowledge on sharepoint, I only manage to get myself authenticated with sharepoint using my account, but I don't know how to say upload a file into sharepoint.

are you able to give me a simple example how to upload a file into sharepoint using your phpSPO library?

1
  • This implementation is very useful. Executed with no error. I have one question. I created a file and uploaded to sharepoint by giving my sharepoint URL. However, I cannot fine the file I uploaded. It does not show up in my folder on sharepoint. My question is what URL should I enter in setting? Thanks.
    – hhtoo
    Mar 30, 2021 at 19:15

1 Answer 1

3

The below example demonstrates how to upload a file using SharePoint REST client for PHP:

$authCtx = new AuthenticationContext($webUrl);
$authCtx->acquireTokenForUser($userName,$password);
$ctx = new ClientContext($webUrl,$authCtx);

$localFilePath = "./data/user guide.docx";
$targetFileUrl = "Documents/user guide.docx";
$fileContent = file_get_contents($localFilePath);
File::saveBinary($ctx,$targetFileUrl,$fileContent);
print "File has been uploaded\r\n";

More examples that demonstrates how to perform operations with files could be found here

7
  • 1
    @wayzz, let me verify it, will get back to you Aug 10, 2016 at 11:44
  • 1
    the error i am getting is this - The expression "web/lists(guid'dfeab1cd-904a-4816-9abf-0ad6ce31e630')/rootFolder/Files/add(overwrite=,url='test.pdf')" is not valid. . Hope this helps.
    – wayzz
    Aug 11, 2016 at 8:11
  • 2
    @wayzz, sure it was, thanks! Apparently it was an issue with resource url, the issue has been resolved in the latest version. Aug 18, 2016 at 11:38
  • 2
    In this particular case it was caused by missing overwrite parameter, I was not able to detect it with unit tests, that is why your comment was very helpful :) Aug 18, 2016 at 12:44
  • 1
    I see glad to help than :)
    – wayzz
    Aug 18, 2016 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.