/** * Import file entry point by using $this->service * Check POST method & get valid uploaded file */ public function import() { $fileUploadName = "qtiPackage"; if ($this->getRequestMethod() != Request::HTTP_POST) { throw new \common_exception_NotImplemented('Only post method is accepted to import Qti package.'); } if (tao_helpers_Http::hasUploadedFile($fileUploadName)) { $file = tao_helpers_Http::getUploadedFile($fileUploadName); $mimeType = tao_helpers_File::getMimeType($file['tmp_name']); if (!in_array($mimeType, self::$accepted_types)) { $this->returnFailure(new common_exception_BadRequest()); } else { $report = $this->service->importQtiTest($file['tmp_name']); if ($report->getType() === common_report_Report::TYPE_SUCCESS) { $data = array(); foreach ($report as $r) { $values = $r->getData(); $testid = $values->rdfsResource->getUri(); foreach ($values->items as $item) { $itemsid[] = $item->getUri(); } $data[] = array('testId' => $testid, 'testItems' => $itemsid); } return $this->returnSuccess($data); } else { return $this->returnFailure(new common_exception_InconsistentData($report->getMessage())); } } } else { return $this->returnFailure(new common_exception_BadRequest()); } }
/** * */ public function apply() { $cssFileData = $file = \tao_helpers_Http::getUploadedFile('content'); $batchTool = new CssBatchTool($cssFileData['tmp_name']); $report = $batchTool->applyToClass(\taoItems_models_classes_ItemsService::singleton()->getRootClass(), $cssFileData['name']); $this->returnJson($report); }
/** * Upload a file to the item directory * * @throws common_exception_MissingParameter */ public function upload() { if (!$this->hasRequestParameter('uri')) { throw new common_exception_MissingParameter('uri', __METHOD__); } $testUri = $this->getRequestParameter('uri'); $test = new core_kernel_classes_Resource($testUri); if (!$this->hasRequestParameter('lang')) { throw new common_exception_MissingParameter('lang', __METHOD__); } $testLang = $this->getRequestParameter('lang'); if (!$this->hasRequestParameter('path')) { throw new common_exception_MissingParameter('path', __METHOD__); } //TODO path traversal and null byte poison check ? $baseDir = taoQtiTest_helpers_ResourceManager::getBaseDir($test); $relPath = trim($this->getRequestParameter('path'), '/'); $relPath = empty($relPath) ? '' : $relPath . '/'; $file = tao_helpers_Http::getUploadedFile('content'); $fileName = $file['name']; if (!move_uploaded_file($file["tmp_name"], $baseDir . $relPath . $fileName)) { throw new common_exception_Error('Unable to move uploaded file'); } $fileData = taoQtiTest_helpers_ResourceManager::buildFile($test, $testLang, $relPath . $fileName); echo json_encode($fileData); }
/** * Upload a file to the item directory * * @throws common_exception_MissingParameter */ public function upload() { //as upload may be called multiple times, we remove the session lock as soon as possible try { session_write_close(); if ($this->hasRequestParameter('uri')) { $itemUri = $this->getRequestParameter('uri'); $item = new core_kernel_classes_Resource($itemUri); } if ($this->hasRequestParameter('lang')) { $itemLang = $this->getRequestParameter('lang'); } if (!$this->hasRequestParameter('path')) { throw new common_exception_MissingParameter('path', __METHOD__); } if (!$this->hasRequestParameter('filters')) { throw new common_exception_MissingParameter('filters', __METHOD__); } $filters = explode(',', $this->getRequestParameter('filters')); $resolver = new ItemMediaResolver($item, $itemLang); $asset = $resolver->resolve($this->getRequestParameter('relPath')); $file = tao_helpers_Http::getUploadedFile('content'); $fileTmpName = $file['tmp_name'] . '_' . $file['name']; if (!tao_helpers_File::copy($file['tmp_name'], $fileTmpName)) { throw new common_exception_Error('impossible to copy ' . $file['tmp_name'] . ' to ' . $fileTmpName); } $mime = \tao_helpers_File::getMimeType($fileTmpName); if (in_array($mime, $filters)) { $filedata = $asset->getMediaSource()->add($fileTmpName, $file['name'], $asset->getMediaIdentifier()); } else { throw new \oat\tao\helpers\FileUploadException('The file you tried to upload is not valid'); } $this->returnJson($filedata); return; } catch (\oat\tao\model\accessControl\data\PermissionException $e) { $message = $e->getMessage(); } catch (\oat\tao\helpers\FileUploadException $e) { $message = $e->getMessage(); } catch (common_Exception $e) { common_Logger::w($e->getMessage()); $message = _('Unable to upload file'); } $this->returnJson(array('error' => $message)); }
/** * Convert uploaded resource to base 64 code * * @return mixed */ public function convert() { $resource = $file = \tao_helpers_Http::getUploadedFile('content'); $base64Converter = new Base64ConverterModel($resource); $this->returnJson($base64Converter->convertToBase64()); }
/** * Return a valid uploaded file * * @return string * @throws \common_Exception * @throws \common_exception_Error * @throws \common_exception_MissingParameter * @throws \common_exception_BadRequest * @throws \oat\tao\helpers\FileUploadException */ protected function getUploadedPackage() { if (!$this->hasRequestParameter(self::RESTITEM_PACKAGE_NAME)) { throw new \common_exception_MissingParameter(self::RESTITEM_PACKAGE_NAME, __CLASS__); } $file = \tao_helpers_Http::getUploadedFile(self::RESTITEM_PACKAGE_NAME); if (!in_array($file['type'], self::$accepted_types)) { throw new \common_exception_BadRequest('Uploaded file has to be a valid archive.'); } $pathinfo = pathinfo($file['tmp_name']); $destination = $pathinfo['dirname'] . DIRECTORY_SEPARATOR . $file['name']; \tao_helpers_File::move($file['tmp_name'], $destination); return $destination; }
/** * Add a new custom interaction from the uploaded zip package */ public function add() { //as upload may be called multiple times, we remove the session lock as soon as possible session_write_close(); try { $file = \tao_helpers_Http::getUploadedFile('content'); } catch (\common_exception_Error $e) { throw new PortableElementParserException('Unable to handle uploaded package.', 0, $e); } $portableElement = $this->getService()->import(PciModel::PCI_IDENTIFIER, $file['tmp_name']); $this->returnJson($this->getMinifiedModel($portableElement)); }
/** * Upload a file to the item directory * * @throws common_exception_MissingParameter */ public function upload() { //as upload may be called multiple times, we remove the session lock as soon as possible session_write_close(); $options = array(); if ($this->hasRequestParameter('uri')) { $itemUri = $this->getRequestParameter('uri'); $item = new core_kernel_classes_Resource($itemUri); $options['item'] = $item; } if ($this->hasRequestParameter('lang')) { $itemLang = $this->getRequestParameter('lang'); $options['lang'] = $itemLang; } if (!$this->hasRequestParameter('path')) { throw new common_exception_MissingParameter('path', __METHOD__); } $relPath = ''; if ($this->hasRequestParameter('relPath')) { $relPath = $this->getRequestParameter('relPath'); } //if the string contains something else than letters, numbers or / throw an exception if (!preg_match('#^$|^[\\w\\/\\-\\._]+$#', $relPath)) { throw new InvalidArgumentException('The request parameter is invalid'); } if (strpos($relPath, '/') === false) { $identifier = $relPath; $subPath = '/'; } else { $identifier = substr($relPath, 0, strpos($relPath, '/')); $subPath = substr($relPath, strpos($relPath, '/') + 1); } $identifier = trim($identifier); $subPath = empty($subPath) ? '' : $subPath . '/'; $clazz = $this->getManagementImplementationClass($identifier); $mediaManagement = new $clazz($options); $file = tao_helpers_Http::getUploadedFile('content'); if (!is_uploaded_file($file['tmp_name'])) { throw new common_exception_Error('Non uploaded file "' . $file['tmp_name'] . '" returned from tao_helpers_Http::getUploadedFile()'); } $filedata = $mediaManagement->add($file['tmp_name'], $file['name'], $subPath); echo json_encode($filedata); }
public function upload() { if (!$this->hasRequestParameter('content')) { throw new \common_exception_MissingParameter('content'); } $file = \tao_helpers_Http::getUploadedFile('content'); $filename = $this->getPlatformService()->storeFile($file['tmp_name'], 'platformtheme.css'); $theme = $this->getPlatformService()->retrieveThemingConfig(); $theme['css-file'] = $filename; $this->getPlatformService()->syncThemingConfig($theme); $this->returnJson(array('success' => __('Style modified'))); }