public function upload_attachment_action() { if ($GLOBALS['user']->id === "nobody") { throw new AccessDeniedException(); } if (!$GLOBALS['ENABLE_EMAIL_ATTACHMENTS']) { throw new AccessDeniedException(_('Mailanhänge sind nicht erlaubt.')); } $file = studip_utf8decode($_FILES['file']); $output = array('name' => $file['name'], 'size' => $file['size']); $output['message_id'] = Request::option("message_id"); if (!validate_upload($file)) { list($type, $error) = explode("§", $GLOBALS['msg']); throw new Exception($error); } $document = new StudipDocument(); $document->setValue('range_id', 'provisional'); $document->setValue('seminar_id', $GLOBALS['user']->id); $document->setValue('name', $output['name']); $document->setValue('filename', $document->getValue('name')); $document->setValue('filesize', (int) $output['size']); $document->setValue('autor_host', $_SERVER['REMOTE_ADDR']); $document->setValue('user_id', $GLOBALS['user']->id); $document->setValue('description', Request::option('message_id')); $success = $document->store(); if (!$success) { throw new Exception("Unable to handle uploaded file."); } $file_moved = move_uploaded_file($file['tmp_name'], get_upload_file_path($document->getId())); if (!$file_moved) { throw new Exception("No permission to move file to destination."); } $output['document_id'] = $document->getId(); $output['icon'] = GetFileIcon(getFileExtension($output['name']))->asImg(['class' => "text-bottom"]); $this->render_json($output); }