Phundament-Packages
[ class tree: Phundament-Packages ] [ index: Phundament-Packages ] [ all elements ]

Source for file LMediaManagerWebUpload.php

Documentation is available at LMediaManagerWebUpload.php

  1. <?php
  2.  
  3. /**
  4.  * class file.
  5.  *
  6.  * @license http://opensource.org/licenses/mozilla1.1.php Mozilla Public License
  7.  * @copyright 2005, diemeisterei GmbH. All rights reserved.
  8.  * @author $Author: schmunk $
  9.  * @version $Revision: 246 $  $Date: 2006-06-01 15:11:24 +0000 (Do, 01 Jun 2006) $
  10.  * @package Phundament.Packages
  11.  * @subpackage LMediaManager
  12.  */
  13.  
  14. /**
  15.  * Provides A Web Upload Component for LMediaManager
  16.  *
  17.  * @package System.Web.UI.WebControls
  18.  * @subpackage Admin
  19.  */
  20.  
  21. class LMediaManagerWebUpload extends TTemplateControl
  22. {
  23.     public function setCategory($value)
  24.     {
  25.         $this->setViewState("category"$valuenull);
  26.     }
  27.  
  28.     public function getCategory()
  29.     {
  30.         return $this->getViewState("category"null);
  31.     }
  32.  
  33.     public function onInit($param)
  34.     {
  35.         $this->Uploader->OnFileUpload[]array (
  36.             $this,
  37.             "fileUploaded"
  38.         );
  39.     }
  40.  
  41.     public function onUploadSucceeded($param)
  42.     {
  43.         $this->raiseEvent('OnUploadSucceeded'$this$param);
  44.     }
  45.  
  46.     private function handleUpload($name$tmpname$overwritefalse)
  47.     {
  48.         $MP$this->Application->getParameters()->itemAt("UploadPath");
  49.  
  50.         // check for existing file
  51.         $md5 md5_file($tmpname);
  52.         $mc new LMediaCriteria;
  53.         $c $mc->build();
  54.         $c->addAnd(LMediaManagerFilesPeer::MD5$md5);
  55.         $result LMediaManagerCore::queryRecords($c);
  56.         if (isset($result[0]))
  57.             return 6;
  58.  
  59.         if (!is_writeable($MP "/"))
  60.             return 2;
  61.  
  62.         $cat $this->getCategory();
  63.         if ($cat !== null)
  64.         {
  65.             $MPC $MP "/" $cat;
  66.             if (!is_writable($MPC "/"))
  67.                 mkdir($MPC);
  68.             if (!is_writable($MPC "/"))
  69.                 return 1;
  70.             $MP $MPC;
  71.         }
  72.         if (is_file($MP "/" $name))
  73.         {
  74.             if (!$overwrite)
  75.                 return 3;
  76.             if (!unlink($MP "/" $name))
  77.                 return 4;
  78.         }
  79.         if (!move_uploaded_file($tmpname$MP "/" $name))
  80.             return 5;
  81.  
  82.         $core new LMediaManagerCore();
  83.         $core->updateDatabase();
  84.         return 0;
  85.     }
  86.  
  87.     public function fileUploaded($sender$param)
  88.     {
  89.         if (!$sender->HasFile)
  90.             return;
  91.  
  92.         $res$this->handleUpload($sender->FileName$sender->LocalName$this->OverwriteSelector->getChecked());
  93.  
  94.         switch ($res)
  95.         {
  96.             case :
  97.                 $str"Upload succesful.";
  98.                 $this->onUploadSucceeded(null);
  99.                 //$this->Service->reload();
  100.                 break;
  101.             case 1:
  102.                 $str "Directory is not writeable!";
  103.                 break;
  104.             case :
  105.                 $str"Upload Folder is not writable!";
  106.                 break;
  107.             case :
  108.                 $str"File exists!";
  109.                 break;
  110.             case :
  111.                 $str"Can not delete exisiting file!";
  112.                 break;
  113.             case :
  114.                 $str"Error while moving uploaded file!";
  115.                 break;
  116.             case :
  117.                 $str"File was not uploaded! Same file already exists in database.";
  118.                 break;
  119.         }
  120.  
  121.         $this->UploadResult->Controls[]"$res$str;
  122.         $um $this->Application->getModule("user_message");
  123.         if ($um !== null$um->add($str,1);
  124.     }
  125.  
  126. }
  127. ?>

Documentation generated on Sun, 25 Feb 2007 16:10:58 +0100 by phpDocumentor 1.3.1