本文整理汇总了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));
}