本文整理汇总了PHP中UTIL_File::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP UTIL_File::getExtension方法的具体用法?PHP UTIL_File::getExtension怎么用?PHP UTIL_File::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UTIL_File
的用法示例。
在下文中一共展示了UTIL_File::getExtension方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTemplate
public function addTemplate($fileName, $roleIds = null, $default = false)
{
$canvasWidth = self::CANVAS_WIDTH;
$canvasHeight = $this->config['cover_height'];
$coverImage = new UTIL_Image($fileName);
$imageHeight = $coverImage->getHeight();
$imageWidth = $coverImage->getWidth();
$css = array('width' => 'auto', 'height' => 'auto');
$tmp = $canvasWidth * $imageHeight / $imageWidth;
if ($tmp >= $canvasHeight) {
$css['width'] = '100%';
} else {
$css['height'] = '100%';
}
$template = new UHEADER_BOL_Template();
$extension = UTIL_File::getExtension($fileName);
$template->file = uniqid('template-') . '.' . $extension;
$template->default = $default;
$template->timeStamp = time();
$dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
$template->setSettings(array('dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
$this->service->saveTemplate($template);
if ($roleIds !== null) {
$this->service->saveRoleIdsForTemplateId($template->id, $roleIds);
}
$templatePath = $this->service->getTemplatePath($template);
OW::getStorage()->copyFile($fileName, $templatePath);
}
示例2: import
public function import($params)
{
$importDir = $params['importDir'];
$txtFile = $importDir . 'configs.txt';
// import configs
if (file_exists($txtFile)) {
$string = file_get_contents($txtFile);
$configs = json_decode($string, true);
}
if (!$configs) {
return;
}
$attachmentService = FORUM_BOL_PostAttachmentService::getInstance();
$attDir = OW::getPluginManager()->getPlugin('forum')->getUserFilesDir();
$attachments = $attachmentService->findAllAttachments();
if (!$attachments) {
return;
}
foreach ($attachments as $file) {
OW::getDbo()->query("SELECT 1 ");
$ext = UTIL_File::getExtension($file->fileName);
$path = $attachmentService->getAttachmentFilePath($file->id, $file->hash, $ext);
$fileName = str_replace($attDir, '', $path);
$content = file_get_contents($configs['url'] . '/' . $fileName);
if (mb_strlen($content)) {
OW::getStorage()->fileSetContent($path, $content);
}
}
}
示例3: includeStaticFile
public function includeStaticFile($file)
{
$document = OW::getDocument();
$staticUrl = $this->plugin->getStaticUrl();
$ext = UTIL_File::getExtension($file);
$file .= "?" . $this->plugin->getDto()->build;
switch ($ext) {
case "css":
$document->addStyleSheet($staticUrl . $file);
break;
case "js":
$document->addScript($staticUrl . $file);
break;
}
}
示例4: addFile
public function addFile(MAILBOX_BOL_FileUpload $dto, $filePath)
{
$ext = UTIL_File::getExtension($dto->fileName);
if (!$this->fileExtensionIsAllowed($ext) && !file_exists($filePath)) {
return false;
}
$uploadPath = $this->getUploadFilePath($dto->hash, $ext);
$dto->filePath = $uploadPath;
$this->saveOrUpdate($dto);
$attId = $dto->id;
if (move_uploaded_file($filePath, $uploadPath)) {
@chmod($uploadPath, 0666);
return true;
} else {
$this->uploadFileDao->deleteById($attId);
return false;
}
}
示例5: renderInput
/**
* @see FormElement::renderInput()
*
* @param array $params
* @return string
*/
public function renderInput($params = null)
{
parent::renderInput($params);
$fileElementId = $this->getId() . '_file';
$entityId = $this->getValue();
if (empty($entityId)) {
$entityId = uniqid('upload');
}
$iframeUrl = OW::getRouter()->urlFor('MAILBOX_CTRL_Mailbox', 'fileUpload', array('entityId' => $entityId, 'formElementId' => $fileElementId));
$attachFileHtml = '<div id="file_attachment" class="ow_mailbox_attachment">
<span class="ow_mailbox_attachment_icon ow_ic_attach "> </span>
<a class="file" href="javascript://"></a> (<span class="filesize"></span>)
<a rel="40" class="ow_delete_attachment ow_lbutton ow_hidden" href="javascript://" style="display: none;">' . OW::getLanguage()->text('mailbox', 'attache_file_delete_button') . '</a>
</div>';
$fileList = array();
if (!empty($entityId)) {
$fileService = MAILBOX_BOL_FileUploadService::getInstance();
$uploadFileDtoList = $fileService->findUploadFileList($entityId);
foreach ($uploadFileDtoList as $uploadFileDto) {
$file = array();
$file['hash'] = $uploadFileDto->hash;
$file['filesize'] = round($uploadFileDto->fileSize / 1024, 2) . 'Kb';
$file['filename'] = $uploadFileDto->fileName;
$file['fileUrl'] = $fileService->getUploadFileUrl($uploadFileDto->hash, UTIL_File::getExtension($uploadFileDto->fileName));
$fileList[] = $file;
}
}
$params = array('elementId' => $fileElementId, 'ajaxResponderUrl' => OW::getRouter()->urlFor("MAILBOX_CTRL_Mailbox", "responder"), 'fileResponderUrl' => $iframeUrl, 'attachFileHtml' => $attachFileHtml, 'fileList' => $fileList);
$script = " window.fileUpload_" . $this->getId() . " = new fileUpload(" . json_encode($params) . ");\n window.fileUpload_" . $this->getId() . ".init();";
OW::getDocument()->addOnloadScript($script);
OW::getDocument()->addScript(OW::getPluginManager()->getPlugin("mailbox")->getStaticJsUrl() . 'ajax_file_upload.js');
$hiddenAttr = array('id' => $this->getId(), 'type' => 'hidden', 'name' => $this->getName(), 'value' => $entityId);
$fileAttr = $this->attributes;
unset($fileAttr['name']);
$fileAttr['id'] = $fileElementId;
return UTIL_HtmlTag::generateTag('input', $hiddenAttr) . '<span class="' . $fileElementId . '_class">' . UTIL_HtmlTag::generateTag('input', $fileAttr) . '</span>
<div id="' . $fileElementId . '_list" class="ow_small ow_smallmargin">
<div class="ow_attachments_label mailbox_attachments_label ow_hidden">' . OW::getLanguage()->text('mailbox', 'attachments') . ' :</div>
</div>';
}
示例6: getFileNameList
public function getFileNameList($dirPath, $prefix = null, array $fileTypes = null)
{
$dirPath = UTIL_File::removeLastDS($dirPath);
$resultList = array();
$handle = opendir($dirPath);
while (($item = readdir($handle)) !== false) {
if ($item === '.' || $item === '..') {
continue;
}
if ($prefix != null) {
$prefixLength = strlen($prefix);
if (!($prefixLength <= strlen($item) && substr($item, 0, $prefixLength) === $prefix)) {
continue;
}
}
$path = $dirPath . DS . $item;
if ($fileTypes === null || is_file($path) && in_array(UTIL_File::getExtension($item), $fileTypes)) {
$resultList[] = $path;
}
}
closedir($handle);
return $resultList;
}
示例7: deleteAttachmentsByConversationList
/**
*
* @param array $conversationIdList
* @return array<MAILBOX_BOL_Attachment>
*/
public function deleteAttachmentsByConversationList(array $conversationIdList)
{
$attachmentList = $this->attachmentDao->findAttachmentstByConversationList($conversationIdList);
foreach ($attachmentList as $attachment) {
$ext = UTIL_File::getExtension($attachment['fileName']);
$path = $this->getAttachmentFilePath($attachment['id'], $attachment['hash'], $ext);
if (OW::getStorage()->removeFile($path)) {
$this->attachmentDao->deleteById($attachment['id']);
}
}
}
示例8: deleteAttachmentFiles
public function deleteAttachmentFiles()
{
$attachDtoList = $this->attachmentDao->getAttachmentForDelete();
foreach ($attachDtoList as $attachDto) {
/* @var $attachDto MAILBOX_BOL_Attachment */
$ext = UTIL_File::getExtension($attachDto->fileName);
$attachmentPath = $this->getAttachmentFilePath($attachDto->id, $attachDto->hash, $ext, $attachDto->fileName);
try {
OW::getStorage()->removeFile($attachmentPath);
$this->attachmentDao->deleteById($attachDto->id);
} catch (Exception $ex) {
}
}
}
示例9: save
public function save($params)
{
$data = $params['data'];
$authAdapter = new OW_RemoteAuthAdapter($data['facebookId'], 'facebook');
$nonQuestions = array('name', 'email', 'avatarUrl');
$nonQuestionsValue = array();
foreach ($nonQuestions as $name) {
$nonQuestionsValue[$name] = empty($data[$name]) ? null : $data[$name];
unset($data[$name]);
}
$data['realname'] = $nonQuestionsValue['name'];
$email = $nonQuestionsValue['email'];
$password = uniqid();
$user = BOL_UserService::getInstance()->findByEmail($email);
$newUser = false;
if ($user === null) {
$newUser = true;
$username = $this->makeUsername($nonQuestionsValue['name']);
$user = BOL_UserService::getInstance()->createUser($username, $password, $email, null, true);
}
BOL_QuestionService::getInstance()->saveQuestionsData(array_filter($data), $user->id);
if (!empty($nonQuestionsValue['avatarUrl'])) {
$avatarUrl = $nonQuestionsValue['avatarUrl'];
$pluginfilesDir = OW::getPluginManager()->getPlugin('skadateios')->getPluginFilesDir();
$ext = UTIL_File::getExtension($avatarUrl);
$tmpFile = $pluginfilesDir . uniqid('avatar-') . (empty($ext) ? '' : '.' . $ext);
copy($avatarUrl, $tmpFile);
BOL_AvatarService::getInstance()->setUserAvatar($user->id, $tmpFile);
@unlink($tmpFile);
}
if (!$authAdapter->isRegistered()) {
$authAdapter->register($user->id);
}
if ($newUser) {
$event = new OW_Event(OW_EventManager::ON_USER_REGISTER, array('method' => 'facebook', 'userId' => $user->id, 'params' => array()));
OW::getEventManager()->trigger($event);
}
OW::getUser()->login($user->id);
$this->assign('success', true);
$this->respondUserData($user->id);
}
示例10: addFromPhotos
public function addFromPhotos($query)
{
$photoId = $query['photoId'];
$groupId = $query['groupId'];
if (!GHEADER_CLASS_CreditsBridge::getInstance()->credits->isAvaliable(GHEADER_CLASS_Credits::ACTION_ADD)) {
$error = GHEADER_CLASS_CreditsBridge::getInstance()->credits->getErrorMessage(GHEADER_CLASS_Credits::ACTION_ADD);
throw new InvalidArgumentException($error);
}
$sourcePath = GHEADER_CLASS_PhotoBridge::getInstance()->pullPhoto($photoId);
if ($sourcePath === null) {
throw new InvalidArgumentException("The requested photo wasn't find");
}
$canvasWidth = $query['width'];
$canvasHeight = OW::getConfig()->getValue('gheader', 'cover_height');
$coverImage = new UTIL_Image($sourcePath);
$imageHeight = $coverImage->getHeight();
$imageWidth = $coverImage->getWidth();
$css = array('width' => 'auto', 'height' => 'auto');
$tmp = $canvasWidth * $imageHeight / $imageWidth;
if ($tmp >= $canvasHeight) {
$css['width'] = '100%';
} else {
$css['height'] = '100%';
}
$this->validateImage($coverImage, $canvasWidth, $canvasHeight);
$cover = $this->service->findCoverByGroupId($groupId, GHEADER_BOL_Cover::STATUS_TMP);
if ($cover === null) {
$cover = new GHEADER_BOL_Cover();
}
$extension = UTIL_File::getExtension($sourcePath);
$cover->file = uniqid('cover-' . $groupId . '-') . '.' . $extension;
$cover->groupId = $groupId;
$cover->status = GHEADER_BOL_Cover::STATUS_TMP;
$cover->timeStamp = time();
$dimensions = array('height' => $imageHeight, 'width' => $imageWidth);
$cover->setSettings(array('photoId' => $photoId, 'dimensions' => $dimensions, 'css' => $css, 'canvas' => array('width' => $canvasWidth, 'height' => $canvasHeight), 'position' => array('top' => 0, 'left' => 0)));
$this->service->saveCover($cover);
$coverPath = $this->service->getCoverPath($cover);
OW::getStorage()->copyFile($sourcePath, $coverPath);
@unlink($sourcePath);
$coverUrl = $this->service->getCoverUrl($cover);
return array('src' => $coverUrl, 'data' => $cover->getSettings());
}
示例11: setCustomDefaultAvatar
public function setCustomDefaultAvatar($size, $file)
{
$conf = json_decode(OW::getConfig()->getValue('base', 'default_avatar'), true);
$dir = OW::getPluginManager()->getPlugin('base')->getUserFilesDir() . 'avatars' . DS;
$ext = UTIL_File::getExtension($file['name']);
$prefix = 'default_' . ($size == 1 ? self::AVATAR_PREFIX : self::AVATAR_BIG_PREFIX);
$fileName = $prefix . uniqid() . '.' . $ext;
if (is_uploaded_file($file['tmp_name'])) {
$storage = OW::getStorage();
if ($storage->copyFile($file['tmp_name'], $dir . $fileName)) {
if (isset($conf[$size])) {
$storage->removeFile($dir . $conf[$size]);
}
$conf[$size] = $fileName;
OW::getConfig()->saveConfig('base', 'default_avatar', json_encode($conf));
return true;
}
}
return false;
}
示例12: getExtension
private static function getExtension($filenName)
{
if (strrpos($filenName, '.') == 0) {
return null;
}
return UTIL_File::getExtension($filenName);
}
示例13: processPhotoAttachment
public function processPhotoAttachment(array $fileInfo)
{
$language = OW::getLanguage();
$error = false;
if (!OW::getUser()->isAuthenticated() || empty($fileInfo) || !is_uploaded_file($fileInfo['tmp_name'])) {
$error = $language->text('base', 'upload_file_fail');
}
if ($fileInfo['error'] != UPLOAD_ERR_OK) {
switch ($fileInfo['error']) {
case UPLOAD_ERR_INI_SIZE:
$error = $language->text('base', 'upload_file_max_upload_filesize_error');
break;
case UPLOAD_ERR_PARTIAL:
$error = $language->text('base', 'upload_file_file_partially_uploaded_error');
break;
case UPLOAD_ERR_NO_FILE:
$error = $language->text('base', 'upload_file_no_file_error');
break;
case UPLOAD_ERR_NO_TMP_DIR:
$error = $language->text('base', 'upload_file_no_tmp_dir_error');
break;
case UPLOAD_ERR_CANT_WRITE:
$error = $language->text('base', 'upload_file_cant_write_file_error');
break;
case UPLOAD_ERR_EXTENSION:
$error = $language->text('base', 'upload_file_invalid_extention_error');
break;
default:
$error = $language->text('base', 'upload_file_fail');
}
}
if (!in_array(UTIL_File::getExtension($_FILES['attachment']['name']), array('jpeg', 'jpg', 'png', 'gif'))) {
$error = $language->text('base', 'upload_file_extension_is_not_allowed');
}
if ((int) $_FILES['attachment']['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
$error = $language->text('base', 'upload_file_max_upload_filesize_error');
}
if ($error !== false) {
throw new InvalidArgumentException($error);
}
$attachDto = new BOL_Attachment();
$attachDto->setUserId(OW::getUser()->getId());
$attachDto->setAddStamp(time());
$attachDto->setStatus(0);
$this->attachmentDao->save($attachDto);
$fileName = 'attach_' . $attachDto->getId() . '.' . UTIL_File::getExtension($_FILES['attachment']['name']);
$attachDto->setFileName($fileName);
$this->attachmentDao->save($attachDto);
$uploadPath = $this->getAttachmentsDir() . $fileName;
$uploadUrl = $this->getAttachmentsUrl() . $fileName;
try {
$image = new UTIL_Image($fileInfo['tmp_name']);
$image->resizeImage(1000, 1000)->orientateImage()->saveImage($uploadPath);
} catch (Exception $e) {
throw new InvalidArgumentException($language->text('base', 'upload_file_fail'));
}
chmod($uploadPath, 0666);
return array('genId' => $attachDto->getId(), 'url' => $uploadUrl);
}
示例14: index
public function index(array $params = null)
{
$forumService = FORUM_BOL_ForumService::getInstance();
if (!isset($params['id']) || !($postId = (int) $params['id'])) {
throw new Redirect404Exception();
}
$postDto = $forumService->findPostById($postId);
if (!$postDto) {
throw new Redirect404Exception();
}
$userId = OW::getUser()->getId();
$topicId = $postDto->topicId;
$topicDto = $forumService->findTopicById($topicId);
$forumGroup = $forumService->getGroupInfo($topicDto->groupId);
$forumSection = $forumService->findSectionById($forumGroup->sectionId);
$isHidden = $forumSection->isHidden;
if ($isHidden) {
$isModerator = OW::getUser()->isAuthorized($forumSection->entity);
$eventParams = array('entity' => $forumSection->entity, 'entityId' => $forumGroup->entityId, 'action' => 'add_topic');
$event = new OW_Event('forum.check_permissions', $eventParams);
OW::getEventManager()->trigger($event);
$canPost = $event->getData();
//check permissions
$canEdit = OW::getUser()->isAuthorized($forumSection->entity, 'add_topic', $postDto->userId);
} else {
$isModerator = OW::getUser()->isAuthorized('forum');
$canPost = true;
$canEdit = $postDto->userId == OW::getUser()->getId();
}
if ((!$canEdit || !$canPost) && !$isModerator) {
$this->setTemplate(OW::getPluginManager()->getPlugin('base')->getCtrlViewDir() . 'authorization_failed.html');
return;
}
$this->assign('postId', $postId);
$editPostForm = $this->generateEditPostForm($postDto);
$this->addForm($editPostForm);
$lang = OW::getLanguage();
$router = OW::getRouter();
if (OW::getRequest()->isPost() && $editPostForm->isValid($_POST)) {
$values = $editPostForm->getValues();
$postId = (int) $values['post-id'];
$text = $values['text'];
$topicId = (int) $values['topic'];
$topicUrl = OW::getRouter()->urlForRoute('topic-default', array('topicId' => $topicId));
$postDto = $forumService->findPostById($postId);
if ($postDto === null || $postDto->userId != $userId && !$isModerator) {
$this->redirect($topicUrl);
}
//save post
$postDto->text = $text;
$forumService->saveOrUpdatePost($postDto);
//save post edit info
$editPostDto = $forumService->findEditPost($postId);
if ($editPostDto === null) {
$editPostDto = new FORUM_BOL_EditPost();
}
$editPostDto->postId = $postId;
$editPostDto->userId = $userId;
$editPostDto->editStamp = time();
$forumService->saveOrUpdateEditPost($editPostDto);
if (isset($_FILES['attachments']) && count($_FILES['attachments'])) {
$filesArray = $_FILES['attachments'];
$filesCount = count($filesArray['name']);
$attachmentService = FORUM_BOL_PostAttachmentService::getInstance();
$skipped = 0;
$accepted = floatval(OW::getConfig()->getValue('forum', 'attachment_filesize') * 1024 * 1024);
for ($i = 0; $i < $filesCount; $i++) {
if (!strlen($filesArray['tmp_name'][$i])) {
continue;
}
// skip unsupported extensions
$ext = UTIL_File::getExtension($filesArray['name'][$i]);
if (!$attachmentService->fileExtensionIsAllowed($ext)) {
$skipped++;
continue;
}
// skip too big files
if ($filesArray['size'][$i] > $accepted) {
$skipped++;
continue;
}
$attachmentDto = new FORUM_BOL_PostAttachment();
$attachmentDto->postId = $postDto->id;
$attachmentDto->fileName = htmlspecialchars($filesArray['name'][$i]);
$attachmentDto->fileNameClean = UTIL_File::sanitizeName($attachmentDto->fileName);
$attachmentDto->fileSize = $filesArray['size'][$i];
$attachmentDto->hash = uniqid();
$added = $attachmentService->addAttachment($attachmentDto, $filesArray['tmp_name'][$i]);
if (!$added) {
$skipped++;
}
}
if ($skipped) {
OW::getFeedback()->warning($lang->text('forum', 'not_all_attachments_added'));
$this->redirect();
}
}
$this->redirect($forumService->getPostUrl($topicId, $postId, true));
}
$enableAttachments = OW::getConfig()->getValue('forum', 'enable_attachments');
//.........这里部分代码省略.........
示例15: imageUploader
public function imageUploader($file, $query)
{
$error = false;
$language = OW::getLanguage();
if (!UTIL_File::validateImage($file['name'])) {
$error = $language->text('base', 'upload_file_extension_is_not_allowed');
}
if ((int) $file['size'] > (double) OW::getConfig()->getValue('base', 'tf_max_pic_size') * 1024 * 1024) {
$error = $language->text('base', 'upload_file_max_upload_filesize_error');
}
if ($error) {
return array('type' => 'uploadError', 'error' => $error, 'result' => $file);
}
$service = BOL_AttachmentService::getInstance();
$attachDto = new BOL_Attachment();
$attachDto->setUserId(OW::getUser()->getId());
$attachDto->setAddStamp(time());
$attachDto->setStatus(0);
$service->saveAttachment($attachDto);
$fileName = 'attach_' . $attachDto->getId() . '.' . UTIL_File::getExtension($file['name']);
$attachDto->setFileName($fileName);
$service->saveAttachment($attachDto);
$uploadPath = $service->getAttachmentsTempDir() . $fileName;
$uploadUrl = $service->getAttachmentsTempUrl() . $fileName;
if (!move_uploaded_file($file['tmp_name'], $uploadPath)) {
return array('type' => 'uploadError', 'error' => $language->text('base', 'upload_file_fail'), 'result' => $file);
}
@chmod($uploadPath, 0666);
$markup = array('html' => '<img src="' . $uploadUrl . '" />', 'js' => '', 'css' => '');
$content = new EQUESTIONS_CMP_AttPhotoPreview($uploadUrl);
$result = array();
$result['content'] = array('html' => $content->render(), 'js' => '', 'css' => '');
$result['oembed'] = array("type" => "file", 'filePath' => $uploadPath, "fileId" => $attachDto->getId());
$response = array('content' => $markup, 'type' => 'imageUploader', 'result' => $result);
return $response;
}