Camelot PHP Tools 1.2 for SharePoint released

Visit the official web site to download, http://www.bendsoft.com/downloads/sharepoint-php-tools/.

Highlights in this update

On public demand we implemented two new methods in the Camelot WCF Service; UploadFile and DownloadFile. And the focus of this release of the PHP Tools have been to implement the support for these methods.

Requirements

Noticeable changes since the previous version

  • The attribute connString has been renamed to connectionString
  • See the full changelog here.

Upload and download files from SharePoint with PHP

Integrating SharePoint Document Libraries and PHP is a time consuming task and the result often ends up in a proprietary integration explicitly designed to work with a specific Document Library, and sometimes even with a preselected folder in the given Document Library.

Using the Camelot Suite for SharePoint this behavior is gone and the opportunity is given to build your integration as it should be. Safe, flexible and non-proprietary.

Uploading

Uploading a file requires a multipart/form-data form. When using the standard CamelotUploadFile class the identifier of the input needs to be named as ‘file’.

<form action="wcf_upload.php" method="post" enctype="multipart/form-data">
    Choose a file to upload: <input type="file" name="file" id="file" /> <br />
    <input type="submit" value="Upload File" />
</form>

The CamelotUploadFile class constructor requires three arguments; file, listName, connectionString. These arguments are to be passed on as an array to the object constructor.

// Load all required files for Camelot PHP Tools
require_once 'loader.php';

// Handle upload files
if ($_SERVER['REQUEST_METHOD'] == "POST") {

    try {
        $UploadFile = new CamelotUploadFile(array(
                    "file" => $_FILES,
                    "listName" => 'Shared Documents',
                    "connectionString" => 'sharepoint_connection'
                ));

        if ($UploadFile->result) {
            echo $UploadFile->message;
        } else {
            echo $UploadFile->result;
            echo $UploadFile->message;
        }
    } catch (Exception $exc) {
        echo "<h2>Method unsuccessful :(</h2><ul><ol>Did you set up settings.php?</ol><ol>Check the argument array</ol></ul>";
        echo $exc->getTraceAsString();
    }
}

Downloading

To download a file using the CamelotDownloadFile class requires three arguments to be set ; file, listName, connectionString. These arguments are to be passed on as an array to the object constructor. Use the download_file method to start the file transfer.

if (!isset($_GET["file"]) || $_GET["file"] == "") {
    echo '<p>You must state a file to download. Ex 
          wcf_download.php?file=notes.docx or by using the form below.</p>';
    echo '<form method="get">File name: <input type="text" name="file" /> 
          <input type="submit"></form>';
    die();
}

// Load all required files for Camelot PHP Tools
require_once 'loader.php';

try {
    $download = new CamelotDownloadFile(array(
                "file" => $_GET["file"],
                "listName" => 'Shared Documents',
                "connectionString" => 'sharepoint_connection'
            ));

    $download->download_file();
} catch (Exception $exc) {
    echo "<h2>Method unsuccessful :(</h2><ul><ol>Did you set up settings.php?</ol><ol>Check the argument array</ol></ul>";
    echo $exc->getTraceAsString();
}

 

Easy as that!

This entry was posted in PHP. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>