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?


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

$authCtx = new AuthenticationContext($webUrl);
$ctx = new ClientContext($webUrl,$authCtx);

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

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

| improve this answer | |
  • I have tried this way of uploading this and using the uploadfile function but I am getting a success message but the file is not uploaded. – wayzz Aug 10 '16 at 11:33
  • 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 '16 at 8:11
  • 1
    @wayzz, sure it was, thanks! Apparently it was an issue with resource url, the issue has been resolved in the latest version. – Vadim Gremyachev Aug 18 '16 at 11:38
  • 1
    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 :) – Vadim Gremyachev Aug 18 '16 at 12:44
  • 1
    I see glad to help than :) – wayzz Aug 18 '16 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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