コード例 #1
0
 /**
  * upload image
  *
  * @param  string  $base64
  */
 public function uploadImage($base64 = 'no')
 {
     $tmpFile = tempnam(Tinebase_Core::getTempDir(), '');
     $file = new Zend_Form_Element_File('file');
     $maxsize = $file->getMaxFileSize();
     $sessionId = Tinebase_Core::getSessionId();
     if (move_uploaded_file($_FILES['upload']['tmp_name'], $tmpFile)) {
         $image_id = str_replace(Tinebase_Core::getTempDir() . '/', '', $tmpFile);
         $image_size = filesize($tmpFile);
         if ($base64 === 'yes') {
             // converts image to base64
             try {
                 $image = file_get_contents($tmpFile);
                 $encoded_data = base64_encode($image);
                 echo '{"success":true , "id":"' . $image_id . '", "session_id":"' . $sessionId . '", "size":"' . $image_size . '", "path":"' . $tmpFile . '", "base64":"' . $encoded_data . '"}';
             } catch (Exception $e) {
                 echo '{"success":false, "error":' . $e . description . '}';
             }
         } else {
             echo '{"success":true , "id":"' . $image_id . '", "session_id":"' . $sessionId . '", "size":"' . $image_size . '", "path":"' . $tmpFile . '"}';
         }
     } else {
         echo '{"success":false, "method":"uploadImage", "maxsize":"' . $maxsize . '"}';
     }
 }
 /**
  * set session id for current request in accesslog
  *
  * @param Tinebase_Model_AccessLog $accessLog
  */
 public function setSessionId(Tinebase_Model_AccessLog $accessLog)
 {
     if (in_array($accessLog->clienttype, array(Tinebase_Server_WebDAV::REQUEST_TYPE, ActiveSync_Server_Http::REQUEST_TYPE))) {
         try {
             $previousAccessLog = Tinebase_AccessLog::getInstance()->getPreviousAccessLog($accessLog);
             $accessLog->sessionid = $previousAccessLog->sessionid;
         } catch (Tinebase_Exception_NotFound $tenf) {
             // ignore
         }
     }
     if (empty($accessLog->sessionid)) {
         $accessLog->sessionid = Tinebase_Core::getSessionId();
     } else {
         Tinebase_Core::set(Tinebase_Core::SESSIONID, $accessLog->sessionid);
     }
 }
コード例 #3
0
 /**
  * create new temp file
  * 
  * @param string $_path
  * @param string $_name
  * @param string $_type
  * @param double $_size
  * @param integer $_error
  * @return Tinebase_Model_TempFile
  */
 public function createTempFile($_path, $_name = 'tempfile.tmp', $_type = 'unknown', $_size = 0, $_error = 0)
 {
     // sanitize filename (convert to utf8)
     $filename = Tinebase_Helper::mbConvertTo($_name);
     $id = Tinebase_Model_TempFile::generateUID();
     $tempFile = new Tinebase_Model_TempFile(array('id' => $id, 'session_id' => Tinebase_Core::getSessionId(false), 'time' => Tinebase_DateTime::now()->get(Tinebase_Record_Abstract::ISO8601LONG), 'path' => $_path, 'name' => $filename, 'type' => !empty($_type) ? $_type : 'unknown', 'error' => !empty($_error) ? $_error : 0, 'size' => !empty($_size) ? (double) $_size : (double) filesize($_path)));
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . " tempfile data: " . print_r($tempFile->toArray(), TRUE));
     }
     $this->create($tempFile);
     return $tempFile;
 }