Source for file upload.php

Documentation is available at upload.php

  1. <?
  2.  
  3. /**
  4.  *
  5.  * This uploads a file onto the file server. A web service method can later move the file to the correct location.
  6.  * @license http://www.knowledgetree.com/KPL KnowledgeTree Public License Version 1.1
  7.  * @package KTWEBSERVICE
  8.  */
  9.  
  10. /*
  11.  *
  12.  * The contents of this file are subject to the KnowledgeTree Public
  13.  * License Version 1.1 ("License"); You may not use this file except in
  14.  * compliance with the License. You may obtain a copy of the License at
  15.  * http://www.knowledgetree.com/KPL
  16.  * 
  17.  * Software distributed under the License is distributed on an "AS IS"
  18.  * basis,
  19.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  20.  * for the specific language governing rights and limitations under the
  21.  * License.
  22.  * 
  23.  * The Original Code is: KnowledgeTree Open Source
  24.  * 
  25.  * The Initial Developer of the Original Code is The Jam Warehouse Software
  26.  * (Pty) Ltd, trading as KnowledgeTree.
  27.  * Portions created by The Jam Warehouse Software (Pty) Ltd are Copyright
  28.  * (C) 2007 The Jam Warehouse Software (Pty) Ltd;
  29.  * All Rights Reserved.
  30.  *
  31.  */
  32.  
  33. // TODO: allow for linking of related documents.
  34.  
  35. if (!array_key_exists('session_id',$_POST))
  36. {
  37.     $msg urlencode('Session not specified.');
  38.     print "status_code=1&msg=$msg";
  39.     exit;
  40. }
  41.  
  42.  
  43. if (!array_key_exists('action',$_POST))
  44. {
  45.     $msg urlencode('Action not specified.');
  46.     print "status_code=2&msg=$msg";
  47.     exit;
  48. }
  49.  
  50. $action $_POST['action'];
  51.  
  52. if (!in_array($action,array('C','A')))
  53. {
  54.     $msg urlencode('Invalid action specified.');
  55.     print "status_code=3&msg=$msg";
  56.     exit;
  57. }
  58.  
  59.  
  60. $session_id $_POST['session_id'];
  61.  
  62.  
  63.  
  64. if (count($_FILES== 0)
  65. {
  66.     $msg urlencode('No files have been uploaded.');
  67.     print "status_code=5&msg=$msg";
  68.     exit;
  69. }
  70.  
  71. if ($action == 'C')
  72. {
  73.     if (!array_key_exists('document_id',$_POST))
  74.     {
  75.         $msg urlencode('document not specified.');
  76.         print "status_code=6&msg=$msg";
  77.         exit;
  78.     }
  79.     $document_id $_POST['document_id'];
  80. }
  81.  
  82. //require_once('../config/dmsDefaults.php');
  83. require_once('../ktapi/ktapi.inc.php');
  84. require_once('KTUploadManager.inc.php');
  85.  
  86.  
  87. $ktapi new KTAPI();
  88.  
  89. $session $ktapi->get_active_session($session_id);
  90.  
  91. if (PEAR::isError($session))
  92. {
  93.     $msg urlencode($session->getMessage());
  94.     print "status_code=4&msg=$msg";
  95.     exit;
  96. }
  97.  
  98. $upload_manager new KTUploadManager();
  99.  
  100. $upload_manager->cleanup();
  101.  
  102. $upload_manager->set_session($session);
  103.  
  104. $added=array();
  105. foreach($_FILES as $key =>$file)
  106. {
  107.     $filename=$file['name'];
  108.     $tempfile=$file['tmp_name'];
  109.      
  110.     $error=$file['error'];
  111.     if ($error == UPLOAD_ERR_OK)
  112.     {        
  113.         $result $upload_manager->uploaded($filename$tempfile$action);
  114.         if (PEAR::isError($result))
  115.         {
  116.             continue;
  117.         }
  118.         if ($result !== false)
  119.         {
  120.             $file['tmp_name'$result;
  121.             $added[$key]=$file;
  122.         
  123.     }
  124. }
  125.  
  126. $added=urlencode(serialize($added));
  127. print "status_code=0&upload_status=$added";
  128.  
  129.  
  130. ?>

Documentation generated on Sun, 22 Apr 2007 02:31:01 +0200 by phpDocumentor 1.3.2