Difference between revisions of "PHP AutoImport"

From OpenKM Documentation
Jump to: navigation, search
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

Revision as of 10:24, 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);
?>