3

I am a newbie for Sharepoint(website developer).I want to connect some Php app to Sharepoint(installed in server) so that for every websites I create there is a connection to Sharepoint.How can I do this.

Any help/suggestions are welcome.Thanks in advance.

2
  • 2
    Your requirement is very vague but your best bet is probably SharePoint web services. Can you provide some details?
    – Chloraphil
    Commented Jul 9, 2013 at 13:21
  • @ chloraphil i want to interact with sharepoint site using php but before that i think i need to make a connection between the two. Reading list items, uploading can only be done when i make a connection between the two, isn't it?? Right now I am confused about how to connect php with sharepoint. Commented Jul 10, 2013 at 4:23

2 Answers 2

3

You can use NuSOAP, a SOAP Toolkit for PHP, to connect to SharePoint. With that reference, in your PHP solution, you can read SharePoint list items or create new list items from PHP. The following code example comes from David Dudok de Wit's blog on creating list items:

<?php

// Requires the NuSOAP library
require_once('lib/nusoap.php');

$username = 'yourUsername';
$password = 'yourPassword';
$rowLimit = '150';

/* A string that contains either the display name or the GUID for the list.
 * It is recommended that you use the GUID, which must be surrounded by curly
 * braces ({}).
 */
$listName = "TempList";

/*
 * Example field (aka columns) names and values, that will be used in the
 * CAML query. The values are the attributes of a single list item here.
 * If the field name contains a space in SharePoint, replace it
 * here with _x0020_ (including underscores).
 */
$field1Name = "Title";
$field2Name = "Address";
$field3Name = "Premium_x0020_customer";

$field1Value = "John Smith";
$field2Value = "USA";
$field3Value = "1";

/* Local path to the Lists.asmx WSDL file (localhost). You must first download
 * it manually from your SharePoint site (which should be available at
 * yoursharepointsite.com/subsite/_vti_bin/Lists.asmx?WSDL)
 */
$wsdl = "http://localhost/phpsp/Lists.wsdl";

//Basic authentication is normally used when using a local copy a the WSDL. Using UTF-8 to allow special characters.
$client = new nusoap_client($wsdl, true);
$client->setCredentials($username,$password);
$client->soap_defencoding='UTF-8';

//CAML query (request), add extra Fields as necessary
$xml ="
 <UpdateListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
 <listName>$listName</listName>
 <updates>
 <Batch ListVersion='1' OnError='Continue'>
 <Method Cmd='New' ID='1'>
 <Field Name='$field1Name'>$field1Value</Field>
 <Field Name='$field2Name'>$field2Value</Field>
 <Field Name='$field3Name'>$field3Value</Field>
 </Method>
 </Batch>
 </updates>
 </UpdateListItems>
";

//Invoke the Web Service
$result = $client->call('UpdateListItems', $xml);

//Error check
if(isset($fault)) {
 echo("<h2>Error</h2>". $fault);
}

//extracting the XML data from the SOAP response
$responseContent = utf8_decode(htmlspecialchars(substr($client->response,strpos($client->response, "<"),strlen($client->response)-1), ENT_QUOTES));

echo "<h2>Request</h2><pre>" . utf8_decode(htmlspecialchars($client->request, ENT_QUOTES)) . "</pre>";
echo "<h2>Response header</h2><pre>" . utf8_decode(htmlspecialchars(substr($client->response,0,strpos($client->response, "<")))) . "</pre>";
echo "<h2>Response content</h2><pre>".$responseContent."</pre>";

//Debugging info:
//echo("<h2>Debug</h2><pre>" . htmlspecialchars($client->debug_str, ENT_QUOTES) . "</pre>");
unset($client);
?>
0

Try Thybab/PHP-SHARePoint-Lists-API api: https://github.com/thybag/PHP-SharePoint-Lists-API

This api allows you get list of all files stored on sharepoint as below:

<?php
include "Thybag\SharePointAPI.php";
include "Thybag\Auth\SharePointOnlineAuth.php";
include "Thybag\Auth\SoapClientAuth.php";
include "Thybag\Auth\StreamWrapperHttpAuth.php";
include "Thybag\Service\ListService.php";
include "Thybag\Service\QueryObjectService.php";
use Thybag\SharePointAPI;
$sp = new SharePointAPI('<[email protected]>','<password>','<path_to_WSDL>,'SPONLINE'); //SPONLINE if your point is online else add true instead
$data = $sp->read('Documents');
var_dump($data);

This will return you the array of all lists stored on sharepoint. Then based on your need you can get the file name by calling array from the above array list like this:

 $max = sizeof($data);
 for($i = 1; $i < $max;$i++)
 {
 $filename = $data[$i];
 echo '<div>';
 $str = $filename["linkfilename"];
 preg_match('"([^\\"]+)"', $str, $result);
 echo $result[0];
 echo "</div>";
 }
3
  • Please don't add the exact same answer to this question, as you did on this one. Instead, try to specify your answer further to make it a better of this specific question. Thank You!
    – Benny Skogberg
    Commented Jan 13, 2017 at 6:56
  • I have just added that he can use or try this api too
    – darkrider
    Commented Jan 13, 2017 at 7:23
  • OK! I've marked the other question as duplicate of this one.
    – Benny Skogberg
    Commented Jan 13, 2017 at 7:29

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.