Page 1 of 1

Strange error thrown by the createSimple function

PostPosted:Tue Mar 10, 2015 4:16 pm
by Skitter
Here's my PHP script:
Code: Select all
<?php
$OKMAuth = new SoapClient('http://localhost:8080/OpenKM/services/OKMAuth?wsdl');
$OKMDocument = new SoapClient('http://localhost:8080/OpenKM/services/OKMDocument?wsdl');
$loginResp = $OKMAuth->login(array('user' => 'okmAdmin', 'password' => 'mypass'));
$token = $loginResp->return;

foreach (glob("/home/test/*") as $filename) {
    $handle = fopen($filename,'rb');
    $file_content = fread($handle,filesize($filename));
    fclose($handle);
    try{
        $OKMDocument->createSimple($token,"/okm:root/file.to.upload",$file_content);
    }
    catch (Exception $e){
        echo $e->getMessage();
    }
  }
$OKMAuth->logout($token);
?>
All I'm trying to do is to send all files from /home/test/ to the /okm:root/ directory. I'm aware of the fact, that they will be overwritten because the file name is constant ('file.to.upload'). The problem is that the createSimple() function is throwing an error which says "Fault occurred while processing.". What am I doing wrong?

Re: Strange error thrown by the createSimple function

PostPosted:Tue Mar 10, 2015 4:28 pm
by Skitter
Damn, sorry for my ignorance. I figured out how to do that. I have to pass the argument list as an array. Here's working code:
Code: Select all
<?php
$OKMAuth = new SoapClient('http://localhost:8080/OpenKM/services/OKMAuth?wsdl');
$OKMDocument = new SoapClient('http://localhost:8080/OpenKM/services/OKMDocument?wsdl');
$loginResp = $OKMAuth->login(array('user' => 'okmAdmin', 'password' => 'mypass'));
$token = $loginResp->return;

foreach (glob("/home/test/*") as $filename) {
    $handle = fopen($filename,'rb');
    $file_content = fread($handle,filesize($filename));
    fclose($handle);
    try{
    	$OKMDocument->createSimple(array('token' => $token, 'docPath' => '/okm:root/blahblah', 'content' => $file_content));
    }
    catch (Exception $e){
        echo $e->getMessage();
    }
}
$OKMAuth->logout($token);
?>

Re: Strange error thrown by the createSimple function

PostPosted:Thu Mar 12, 2015 8:55 am
by jllort
I encourage using SDK for php http://wiki.openkm.com/index.php/SDK_for_PHP in place of webservices based on soap.