Beispiel #1
0
 function onUploadFromData($data, $roo)
 {
     if (empty($data)) {
         $this->err = "Missing file details";
         return false;
     }
     if ($this->id) {
         $this->beforeDelete();
     }
     if (empty($this->ontable)) {
         $this->err = "Missing  ontable";
         return false;
     }
     if (!empty($this->imgtype) && $this->imgtype[0] == '-' && !empty($this->onid)) {
         // then its an upload
         $img = DB_DataObject::factory('Images');
         $img->onid = $this->onid;
         $img->ontable = $this->ontable;
         $img->imgtype = $this->imgtype;
         $img->find();
         while ($img->fetch()) {
             $img->beforeDelete();
             $img->delete();
         }
     }
     require_once 'File/MimeType.php';
     $y = new File_MimeType();
     if (in_array($this->mimetype, array('text/application', 'application/octet-stream', 'image/x-png', 'image/pjpeg', 'application/x-apple-msg-attachment', 'application/vnd.ms-excel', 'application/csv-tab-delimited-table'))) {
         // weird tyeps..
         $inf = pathinfo($this->filename);
         $this->mimetype = $y->fromExt($inf['extension']);
     }
     $ext = $y->toExt(trim((string) $this->mimetype));
     if (array_pop(explode('.', $this->filename)) != $ext) {
         $this->filename = $this->filename . '.' . $ext;
     }
     if (!$this->createFromData($data)) {
         return false;
     }
     return true;
 }