• Home
  • Q&A
  • Connecting to Windows Azure Storage Blob with PHP

Connecting to Windows Azure Storage Blob with PHP

Brennan HattonviaStackOverflow
November 07, 2012
0 score
1 answers

I am trying to upload files to Windows Azure with PHP.

I installed it manually by downloading/extracting the .zip from github and copying the files to my server via ftp. I have been following the tutorial: https://www.windowsazure.com/en-us/develop/php/how-to-guides/blob-service/ I have just copied the sample PHP code, tried to make it work

But I get the error -

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in /home/USERNAME/public_html/FOLDER/FOLDER/FILENAME.php on line 8

I have replaced unnecessary folder/file names above for privacy reasons. I am using the folder that FILENAME.php is located in as a test folder for mucking around with things like this on my server, it is essentially a copy of public_html with the new unpublished content Im working on added to it.

The file in the error I am calling 'FILENAME.php' is almost a copy of the code from the tutorial which looks like this.

require_once 'WindowsAzure/WindowsAzure.php';
//commented out code
//commented out code    
//commented out code
//commented out code

use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;

function SaveBlobAzura()
    // Create blob REST proxy.
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

    $content = fopen("c:\myfile.txt", "r");
    $blob_name = "myblob";

    try {
        //Upload blob
        $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content);
    catch(ServiceException $e){
        // Handle exception based on error codes and messages.
        // Error codes and messages are here: 
        // http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
        $code = $e->getCode();
        $error_message = $e->getMessage();
        echo $code.": ".$error_message."<br />";

Line 8 in the file the error references is a reference to a php class.

use WindowsAzure\Common\ServicesBuilder;

There exists a file called "ServicesBuilder.php" in WindowsAzure\Common\ which indeed has a class called "ServicesBuilder".

But that is where I am stuck.

The Host I am using is http://www.000webhost.com the free plan. Maybe their server has some restriction that prohibit class reference? (I don't think so) But it might say that in an about way that I cant see. The plan spec is on the home page at the bottom.

Any help would be greatly appreciated. :)