Download SharePoint Data Files Using PHP

How to download Files From SharePoint Using php?

This example is useful to download sharepoint file using php. I have try to download sharepoint file using PHP CURL and i have done it so try it.


<?php
$sp_login_id = "test"; // sharepoint user id
$sp_password = "********"; //sharepoint password
$sp_data_file_url = "http://server/test.doc"; // data file url


$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$sp_data_file_url); // set url to post to
curl_setopt($ch, CURLOPT_USERPWD,"$sp_login_id:$sp_password");
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // curl error
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 5000); // times out after 5s
curl_setopt($ch, CURLOPT_GET, 1); // set GET method
$result = curl_exec($ch); // execute the whole process

//curl errors
$curl_info = curl_getinfo($ch);
switch($curl_info["http_code"]){
case 401:
die("Incorect userid or password.");
break;

case 404:
die("Incorect data file URL.");
break;
}

$fo@fopen(basename($sp_data_file_url),"w");
@fwrite($fo,$result);
@fclose($fo);
?>

List of Microsoft SharePoint Web Services

There are 16 web services of SharePoint, which is are as follows.

Web Service for Administrative methods such as creating and deleting sites

http://server:5966/_vti_adm/Admin.asmx

Web Service for working with alerts
http://server/_vti_bin/Alerts.asmx

Web Service for retrieving schemas and data
http://server/_vti_bin/DspSts.asmx

Web Service for working with Document Workspaces
http://server/_vti_bin/DWS.asmx

Web Service for working with user interface forms
http://server/_vti_bin/Forms.asmx

Web Service for working with picture libraries
http://server/_vti_bin/Imaging.asmx

Web Service for working with lists.
http://server/_vti_bin/Lists.asmx

Web Service for working with Meeting Workspaces
http://server/_vti_bin/Meetings.asmx

Web Service for working with SharePoint Services security
http://server/_vti_bin/Permissions.asmx

Web Service for Windows SharePoint Portal Server
http://server/_vti_bin/SiteData.asmx

Web Service for Contains a single method to retrieve site templates
http://server/_vti_bin/Sites.asmx

Web Service for working with users and groups
http://server/_vti_bin/UserGroup.asmx

Web Service for working with file versions
http://server/_vti_bin/versions.asmx

Web Service for working with views of lists
http://server/_vti_bin/Views.asmx

Web Service for working with Web Parts
http://server/_vti_bin/WebPartPages.asmx

Web Service for working with sites and subsites
http://server/_vti_bin/Webs.asmx

What is Microsoft SharePoint ?

Microsoft SharePoint is product of Microsoft. It's browser based document Management System. You can handle many task in SharePoint such as task list or Discussion pane, Web Parts, Meetings Alert etc. SharedPoint allow users to access SharePoint workspace using web Services.

Web Service for Administrative methods such as creating and deleting sites
http://server:5966/_vti_adm/Admin.asmx

Web Service for working with alerts
http://server/_vti_bin/Alerts.asmx

Web Service for retrieving schemas and data
http://server/_vti_bin/DspSts.asmx

Web Service for working with Document Workspaces
http://server/_vti_bin/DWS.asmx

Web Service for working with user interface forms
http://server/_vti_bin/Forms.asmx

Web Service for working with picture libraries
http://server/_vti_bin/Imaging.asmx

Web Service for working with lists.
http://server/_vti_bin/Lists.asmx

Web Service for working with Meeting Workspaces
http://server/_vti_bin/Meetings.asmx

Web Service for working with SharePoint Services security
http://server/_vti_bin/Permissions.asmx

Web Service for Windows SharePoint Portal Server
http://server/_vti_bin/SiteData.asmx

Web Service for Contains a single method to retrieve site templates
http://server/_vti_bin/Sites.asmx

Web Service for working with users and groups
http://server/_vti_bin/UserGroup.asmx

Web Service for working with file versions
http://server/_vti_bin/versions.asmx

Web Service for working with views of lists
http://server/_vti_bin/Views.asmx

Web Service for working with Web Parts
http://server/_vti_bin/WebPartPages.asmx

Web Service for working with sites and subsites
http://server/_vti_bin/Webs.asmx