Codice PHP:
require('SOAP/Client.php');
/* METODI DEL WEBSERVICE
* -- addResource(String TKEY, String url, String username, String pass)
* -- synchronizeFolders(String first, String second, String TKEY)
* -- upload(String encodedFile, String fileName, String To, String TKEY)
* -- Rename(String Path, String oldName, String newName, String TKEY)
* -- getAllResource(String TKEY)
* -- getAllFile(String Resource, String TKEY)
* -- login(String User, String Pass)
* -- getInfo(String Resource, String TKEY)
* -- logout(String TKEY)
* -- addUser(String nick,String pass,String email)
* -- deleteUser(String TKEY)
* -- changeUserPwd(String TKEY, String newpass)
* -- deleteResource(String TKEY, String url, String username, String pass)
* -- changeResource(String TKEY, String url, String username, String pass, String new_url, String new_username, String new_pass)
* -- copy(String From, String To, String TKEY)
* -- delete(String Resource, String TKEY)
* -- move(String From, String To, String TKEY)
* -- download(String From, String TKEY)
*/
class VFSClient{
private $WSDL_URL = 'VFService.wsdl';
private $WSDL;
private $client;
public $tkey;
public $err_msg;
public $res_arr = array();
public $myVSF = array();
public function __construct(){
$this->WSDL = new SOAP_WSDL($this->WSDL_URL);
$this->client = $this->WSDL->getProxy();
}
public function getErrorMessage(){
return $this->err_msg;
}
public function getTKEY(){
return $this->tkey;
}
public function login($username, $password){
$ret = $this->client->login($username,$password);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// LOGIN SUCCESSFUL
$this->tkey = $arr[1];
return true;
} else {
// LOGIN FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function logout(){
$ret = $this->client->logout($this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// LOGOUT SUCCESSFUL
return true;
} else {
// LOGOUT FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function userAdd($username, $password, $email){
$ret = $this->client->addUser($username, $password, $email);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// USERADD SUCCESSFUL
return true;
} else {
// USERADD FAILED - USER NOT ADDED IN DATABASE
$this->err_msg = $arr[1];
return false;
}
}
public function userDel(){
$ret = $this->client->deleteUser($this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// USERDEL SUCCESSFUL
return true;
} else {
// USERDEL FAILED - USER IS STILL IN DATABASE
$this->err_msg = $arr[1];
return false;
}
}
public function userMod($newpassword){
$ret = $this->client->changeUsrPwd($this->tkey, $newpassword);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - PASSWORD CHANGED TO NEWPASSWORD
return true;
} else {
// FAILED - PASSWORD HAS NOT BEEN CHANGED
$this->err_msg = $arr[1];
return false;
}
}
public function resAdd($url, $username, $password){
$ret = $this->client->addResource($this->tkey, $url, $username, $password);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - NEW RESOURCE ADDED IN DATABASE
return true;
} else {
// FAILED - RESOURCE HAS NOT BEEN ADDED
$this->err_msg = $arr[1];
return false;
}
}
public function resDel($url, $username, $password){
$ret = $this->client->changeResource($this->tkey, $url, $username, $password);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - RESOURCE DELETED
return true;
} else {
// FAILED - RESOURCE HAS NOT BEEN DELETED
$this->err_msg = $arr[1];
return false;
}
}
public function resMod($old_url, $old_user, $old_password, $new_url, $new_user, $new_password){
$ret = $this->client->changeResource($this->tkey, $old_url, $old_user, $old_password, $new_url, $new_user, $new_password);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - RESOURCE HAS BEEN CHANGED
return true;
} else {
// FAILED - RESOURCE HAS NOT BEEN CHANGED
$this->err_msg = $arr[1];
return false;
}
}
public function getRes(){
$ret = $this->client->getAllResource($this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS
for($i=1; i<count($arr); $i++){
// MEMORIZZO IL VETTORE DELLE RISORSE DISPONIBILI
$res[$i-1] = $arr[$i];
}
return $res;
} else {
// FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function getFiles($res){
$ret = $this->client->getAllFiles($res, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS
for($i=1; i<count($arr); $i++){
/* Struttura del vettore $files:
* - $files[nomeFile][tipoFile]
* Scorrere il vettore:
* foreach(array_keys($files) as $key){
* $nomeFile = $key;
* $tipoFile = $files[$key]
* }
*/
$files[substr($arr[$i],2)] = $arr[$i]{0};
}
return $files;
} else {
// FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function getFileInfo($file){
$ret = $this->client->getInfo($file, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS
for($i=1; i<count($arr); $i++){
$tmp = explode("$", $arr[$i]);
/* Struttura del vettore $fileInfo:
* - $fileInfo[tipoInfo][valoreInfo]
* Scorrere il vettore:
* foreach(array_keys($fileInfo) as $key){
* $tipoInfo = $key;
* $valoreInfo = $fileInfo[$key]
* }
*/
$fileInfo[$tmp[0]] = $tmp[1];
}
return $fileInfo;
} else {
// FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function copy($src, $dst){
$ret = $this->client->copy($src, $dst, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - COPY DONE
return true;
} else {
// FAILED - COPY FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function move($src, $dst){
$ret = $this->client->move($src, $dst, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - MOVE DONE
return true;
} else {
// FAILED - MOVE FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function remove($file){
$ret = $this->client->delete($file, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - REMOVE DONE
return true;
} else {
// FAILED - REMOVE FAILED
$this->err_msg = $arr[1];
return false;
}
}
public function rename($path, $oldfilename, $newfilename){
$ret = $this->client->rename($path, $oldfilename, $newfilename, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS - RENAME DONE
return true;
} else {
// FAILED - RENAME FAILED
$this->err_msg = $arr[1];
return false;
}
}
// Si deve specificare come secondo parametro il path di destinazione del file scaricato
public function download($src, $dst){
$ret = $this->client->download($src, $this->tkey);
$arr = explode("|", $ret);
if ($arr[0]==1) {
// SUCCESS
/* La funzione download ritorna il nome del file
* ed il file codificato base64 sottoforma di stringa.
*/
$filename = $arr[1];
$data = base64_decode($arr[2]);
$handle = fopen($dst.'/'.$filename, 'w');
if($handle != false){
if(fputs($handle, $data, strlen($data)) != false){
return true;
} else {
// fputs FAILED
return false;
}
} else {
// fopen FAILED
return false;
}
} else {
// FAILED
$this->err_msg = $arr[1];
return false;
}
}
// $file è il path completo del file da uploadare
public function upload($file, $res){
$handle = fopen($file, 'r');
if($handle != false){
$data = fread($handle, filesize($file));
if($data != false){
$base64 = base64_encode($data);
$ret = $this->client->upload($base64, basename($file), $res, $this->tkey);
$arr = explode("|", $ret);
if($arr[0]==1){
//SUCCESS - FILE UPLOADED
return true;
} else {
//FAILED
$this->err_msg = $arr[1];
return false;
}
} else {
// fread FAILED
return false;
}
} else {
//fopen FAILED
return false;
}
}
public function synchronize($dir1, $dir2){
$ret = $this->client->synchronizeFolders($dir1, $dir2, $this->tkey);
$arr = explode("|", $ret);
if($arr[0]==1){
//SUCCESS - FILE UPLOADED
return true;
} else {
//FAILED
$this->err_msg = $arr[1];
return false;
}
}
}
Dal messaggio di errore: