Login Form



SMEStorage php sample PDF Print E-mail

I have did some libs for SMEStorage.com API . Also i communicated with programmers that used SMEStorage API and i found that most difficult thing is to start using this API. For example, creating a folder or uploading a file. And next things are easy is this first tasks are done.

There i will describe how to create folder in SMEStorage with php.

I will create simple php library for this. Full SMEStorage API description should be there http://code.google.com/p/smestorage/

Main file (test.php) that  will test library has code:



//get token for user

 echo 'Can not get token. Maybe login/password incorrect';

//create folder in root
$folderid=createFolder('my test folder','0');

//create subfolder in just created folder
$folderid=createFolder('my test subfolder',$folderid);


Lets analize library lib.php line by line.


global $token;

First line defines API base url.

Then including php class that parses xml. It will be used to parse API response.

And last line there is declaration of the variable where API token will be stored. One get, the token is used for all API calling during a session.
Next part of the code:

function processRequest($request,$data=array()){


 $process = curl_init($url); 
 curl_setopt($process, CURLOPT_USERAGENT, 'SMEStorage client example'); 
 //this is post request
 curl_setopt($process, CURLOPT_POST,     1 );
 curl_setopt($process, CURLOPT_POSTFIELDS, $data); 
 curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
 curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
 $response = curl_exec($process); 
 echo curl_error($process);
 //parse response
 $x=new XmlToArray($response);


 return $result;    

This is function that sends API request and parse response.

The function can be splited for 2 parts: first part sends request and gets response and second part parses xml response.

Function gets API request url and only adds correct API server host to the url. Combining of the url is in response of functions that will call function processRequest .

SMEStorage API url is in format:


Next is function that does user Auth.

function getToken($login,$password){
 global $token;
 $a= processRequest('*/gettoken/'.encodeArgs(array($login,$password)));

 return true;
 return false;

This is function that requests a token for user session. User login and password are sent as arguments.

API request url for getting token is:


There it is needed to describe function encodeArgs that encoded arguments set to required format. Arguments are set without names, so argument order is important. Read more in API manual.

function encodeArgs($args){
 foreach ($args as $ar){
 return join(',',$a);

At last there is function that creates a folder.

API function requires 3 arguments: folder name, folder description and parent folder id.

function createFolder($foldername,$parentid='0'){
 global $token;
 $a= processRequest($token.'/doCreateNewFolder/'.encodeArgs(array(
 $foldername,        //1-st arg is folder name
 '',            //2-nd arg is folder descrition
 $parentid        //3-rd arg is folder parent folder id

 //return new folder id
 return $a[1]['file']['fi_id'];
 return false;

Full example code can be downloaded there in Downloads area - download SMEStorage API sample 1


Last Updated on Friday, 12 February 2010 12:46


#1 federico 2012-03-13 17:42
Utili servizi di consulenza scolastica e recupero anni scolastici per la scuola superiore. [http://www.scuolaonline.com/diploma-online/diploma-online]Diploma Online[/http://www.scuolaonline.com/diploma-online/diploma-online] anche in un solo anno.
Laurea Online in due anni.