当前位置: 首页>>代码示例>>PHP>>正文


PHP tao_helpers_File::getFileExtention方法代码示例

本文整理汇总了PHP中tao_helpers_File::getFileExtention方法的典型用法代码示例。如果您正苦于以下问题:PHP tao_helpers_File::getFileExtention方法的具体用法?PHP tao_helpers_File::getFileExtention怎么用?PHP tao_helpers_File::getFileExtention使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tao_helpers_File的用法示例。


在下文中一共展示了tao_helpers_File::getFileExtention方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: upload

 /**
  * 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 = $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 (is_string($filters)) {
             // the mime type is part of the $filters
             $filters = explode(',', $filters);
             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'));
             }
         } else {
             $valid = false;
             // OR the extension is part of the filter and it correspond to the mime type
             foreach ($filters as $filter) {
                 if ($filter['mime'] === $mime && (!isset($filter['extension']) || $filter['extension'] === \tao_helpers_File::getFileExtention($fileTmpName))) {
                     $valid = true;
                 }
             }
             if ($valid) {
                 $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));
 }
开发者ID:oat-sa,项目名称:extension-tao-item,代码行数:66,代码来源:class.ItemContent.php


注:本文中的tao_helpers_File::getFileExtention方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。