PHP SOAP Webservices samples - Automatic import
Import the PDF files from some local folder /converted/*.pdf path to a specific OpenKM server path.
<?php
// Register WSDL
$OKMAuth = new SoapClient('http://localhost:8080/OpenKM/services/OKMAuth?wsdl');
$OKMDocument = new SoapClient('http://localhost:8080/OpenKM/services/OKMDocument?wsdl');
$OKMFolder = new SoapClient('http://localhost:8080/OpenKM/services/OKMFolder?wsdl');
// Login
$loginResp = $OKMAuth->login(array('user' => 'okmAdmin', 'password' => 'admin'));
$token = $loginResp->return;
foreach (glob("converted/*.pdf") as $filename) {
echo "$filename size " . filesize($filename) . '<br />';
// open file and encode if necessary
$handle = fopen($filename,'rb');
$file_content = fread($handle,filesize($filename));
fclose($handle);
$encoded = base64_encode($file_content);
$filename1 = substr($filename,12);
echo "$filename1" . '<br />';
$OKMDocument->createSimple(array('token' => $token, 'docPath' => "/okm:root/imported/".$filename1, 'content' => $file_content));
//delete the file uoloaded
unlink("c:/converted/".$filename1);
}
// Logout
$OKMAuth->logout($token);
?>