Difference between revisions of "PHP AutoImport"

From OpenKM Documentation
Jump to: navigation, search
(Created page with '<source lang="php"> <?php $okmurl="http://localhost:8080/OpenKM/"; $okmid="autoImport"; $okmpw="upload"; $OKMAuth = new SoapClient($okmurl."OKMAuth?wsdl"); $OKMDocume…')
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
Import pdf files from some local '''/converted/*.pdf''' path to specific OpenKM server path
 +
 
<source lang="php">
 
<source lang="php">
 
<?php
 
<?php
Line 31: Line 33:
 
?>
 
?>
 
</source>
 
</source>
 +
 +
[[Category: Utilities]]

Latest revision as of 10:26, 8 November 2012

Import pdf files from some local /converted/*.pdf path to specific OpenKM server path

<?php
  $okmurl="http://localhost:8080/OpenKM/";
  $okmid="autoImport";
  $okmpw="upload";
 
  $OKMAuth = new SoapClient($okmurl."OKMAuth?wsdl");
  $OKMDocument = new SoapClient($okmurl."OKMDocument?wsdl");

  // Login
  $token = $OKMAuth->login($okmid, $okmpw);

  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($token,"/okm:root/imported/".$filename1,$file_content);
    
    //delete the file uoloaded
    unlink("c:/converted/".$filename1);     
  }

  // Logout
  $OKMAuth->logout($token);
?>