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


PHP MediaHelper::isImage方法代码示例

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


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

示例1: uploadIcon

 /**
  * Upload an icon for a work
  * 
  * @param   KCommandContext A command context object
  * @return  void
  */
 public function uploadIcon(KCommandContext $context)
 {
     $icon = KRequest::get('files.icon', 'raw');
     if (!$icon['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($icon['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $icon['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($icon, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $icon['name'], lcfirst($error)));
         return;
     }
     $slug = $this->getService('koowa:filter.slug');
     $path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/icon/';
     $ext = JFile::getExt($icon['name']);
     $name = JFile::makeSafe($slug->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($icon['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->icon = $path . $name;
 }
开发者ID:ravenlife,项目名称:Portfolio,代码行数:31,代码来源:work.php

示例2: uploadAvatar

 /**
  * Upload the users avatar
  * 
  * @param	KCommandContext	A command context object
  * @return 	void
  */
 public function uploadAvatar(KCommandContext $context)
 {
     $avatar = KRequest::get('files.avatar', 'raw');
     if (!$avatar['name']) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     // is it an image
     if (!MediaHelper::isImage($avatar['name'])) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $avatar['name']));
         return;
     }
     // are we allowed to upload this filetype
     if (!MediaHelper::canUpload($avatar, $error)) {
         JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $avatar['name'], lcfirst($error)));
         return;
     }
     // @todo put in some max file size checks
     $path = 'images/com_portfolio/avatars/' . $context->data->user_id . '/';
     $ext = JFile::getExt($avatar['name']);
     $name = JFile::makeSafe($this->getService('koowa:filter.slug')->sanitize($context->data->title) . '.' . $ext);
     JFile::upload($avatar['tmp_name'], JPATH_ROOT . '/' . $path . $name);
     $context->data->avatar = $path . $name;
 }
开发者ID:ravenlife,项目名称:Portfolio,代码行数:31,代码来源:person.php

示例3: isImage

 /**
  * Returns true if it's an image
  *
  * @return boolean	True if image, false if not
  */
 public function isImage()
 {
     if (!isset($this->_is_image)) {
         //Dirty hack as MediaHelper::isImage mistakenly thinks jpeg files aren't images
         $this->_is_image = MediaHelper::isImage(str_replace('.jpeg', '.jpg', $this->name));
     }
     return $this->_is_image;
 }
开发者ID:ravenlife,项目名称:Ninjaboard,代码行数:13,代码来源:attachment.php

示例4: setAvatar

 public function setAvatar(KCommandContext $context)
 {
     //@TODO we shouldn't clear all cache, only the cache for this user
     if (JFolder::exists(JPATH_ROOT . '/cache/com_ninjaboard/avatars')) {
         JFolder::delete(JPATH_ROOT . '/cache/com_ninjaboard/avatars');
     }
     //If nothing is uploaded, don't execute
     if (!KRequest::get('files.avatar.name', 'raw')) {
         return;
     }
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     $person = KFactory::tmp('admin::com.ninjaboard.model.people')->id($context->result->id)->getItem();
     $error = null;
     $errors = array();
     $identifier = $this->getIdentifier();
     $name = $identifier->type . '_' . $identifier->package;
     $relative = '/media/' . $name . '/images/avatars/' . $person->id . '/';
     $absolute = JPATH_ROOT . $relative;
     $attachments = array();
     $avatar = KRequest::get('files.avatar', 'raw');
     //if we are a bmp we cant upload it
     if (strtolower(JFile::getExt($avatar['name'])) == 'bmp') {
         JError::raiseWarning(21, sprintf(JText::_('%s failed to upload because this file type is not supported'), $avatar['name']));
         return $this;
     }
     if (!MediaHelper::canUpload($avatar, $error)) {
         $message = JText::_("%s failed to upload because %s");
         JError::raiseWarning(21, sprintf($message, $avatar['name'], lcfirst($error)));
         return $this;
     }
     if (!MediaHelper::isImage($avatar['name'])) {
         $message = JText::_("%s failed to upload because it's not an image.");
         JError::raiseWarning(21, sprintf($message, $avatar['name']));
         return $this;
     }
     $this->params = KFactory::get('admin::com.ninjaboard.model.settings')->getParams();
     $params = $this->params['avatar_settings'];
     $maxSize = (int) $params['upload_size_limit'];
     if ($maxSize > 0 && (int) $avatar['size'] > $maxSize) {
         $message = JText::_("%s failed uploading because it's too large.");
         JError::raiseWarning(21, sprintf($message, $avatar['name']));
         return $this;
     }
     $upload = JFile::makeSafe(uniqid(time())) . '.' . JFile::getExt($avatar['name']);
     JFile::upload($avatar['tmp_name'], $absolute . $upload);
     $person->avatar = $relative . $upload;
     $person->avatar_on = gmdate('Y-m-d H:i:s');
     $person->save();
     return $this;
 }
开发者ID:ravenlife,项目名称:Ninjaboard,代码行数:51,代码来源:user.php

示例5: _afterSave

 /**
  * Method for uploading files on save
  * 
  * @param   KCommandContext A command context object
  * @return  void
  */
 public function _afterSave(KCommandContext $context)
 {
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     $item = $this->getModel()->getItem();
     KRequest::set('files.icon', null);
     foreach (KRequest::get('files', 'raw') as $key => $file) {
         if ($file['error'] != UPLOAD_ERR_OK || !$file) {
             continue;
         }
         // are we allowed to upload this filetype
         if (!MediaHelper::canUpload($file, $error)) {
             JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because %s"), $file['name'], lcfirst($error)));
             return;
         }
         $slug = $this->getService('koowa:filter.slug');
         $ext = JFile::getExt($file['name']);
         $name = $slug->sanitize(JFile::stripExt($file['name'])) . '-' . time() . '.' . $ext;
         $name = JFile::makeSafe($name);
         $path = 'images/com_portfolio/work/' . $slug->sanitize($context->data->title) . '/';
         // if this is an image, check we are allowed to upload it
         if (strpos($key, 'image') === false) {
             $path .= 'files/';
             $row = $this->getService('com://admin/portfolio.database.row.file');
         } else {
             if (!MediaHelper::isImage($file['name'])) {
                 JError::raiseWarning(21, sprintf(JText::_("%s failed to upload because it's not an image."), $file['name']));
                 return;
             }
             $path .= 'images/';
             $row = $this->getService('com://admin/portfolio.database.row.image');
             $this->generateThumb($file, JPATH_ROOT . '/' . $path . 'thumb-' . $name);
         }
         JFile::upload($file['tmp_name'], JPATH_ROOT . '/' . $path . $name);
         $row->setData(array('directory' => $path, 'filename' => $name, 'work_id' => $item->id))->save();
     }
 }
开发者ID:ravenlife,项目名称:Portfolio,代码行数:43,代码来源:fileable.php

示例6: _upload

 /**
  * Helper method for uploading a file
  *
  * @author Stian Didriksen <stian@ninjaforge.com>
  * @param  array $config		Configuration array
  *					->name		Where to find the file object in $_FILES
  *					->to		Where the file upload destination
  *					->rename	If given a string, that will be the new name, false to keep the current name
  *					->randomize	Wether to create a random name for the uploaded file or not
  *					->image		Set to true if an additional image validation is needed
  *					->root		The root of the move operation, change this if you need to go up the root
  * @return array				Result of the operation
  */
 protected function _upload(array $config)
 {
     $config = new KConfig($config);
     $identifier = $this->getIdentifier();
     $package = $identifier->package;
     $folder = KInflector::pluralize($identifier->name);
     $config->append(array('name' => 'image', 'to' => '/images/stories/com_' . $package . '/' . $folder . '/', 'rename' => false, 'randomize' => false, 'image' => false, 'root' => JPATH_ROOT));
     //Prepare MediaHelper
     JLoader::register('MediaHelper', JPATH_ROOT . '/components/com_media/helpers/media.php');
     $error = null;
     $file = KRequest::get('files.' . $config->name, 'raw');
     if (!MediaHelper::canUpload($file, $error)) {
         $message = JText::_("%s failed to upload because %s");
         JError::raiseWarning(21, sprintf($message, $file['name'], lcfirst($error)));
         return array();
     }
     if ($config->image && !MediaHelper::isImage($file['name'])) {
         $message = JText::_("%s failed to upload because it's not an image.");
         JError::raiseWarning(21, sprintf($message, $file['name']));
         return array();
     }
     $name = $config->rename ? $config->rename : $file['name'];
     $upload = JFile::makeSafe($config->randomize ? uniqid(time()) . '.' . JFile::getExt($name) : $name);
     $relative = $config->to . $upload;
     $absolute = $config->root . $relative;
     JFile::upload($file['tmp_name'], $absolute);
     return array('filename' => $upload, 'filepath' => array('relative' => $relative, 'absolute' => $absolute));
 }
开发者ID:ravenlife,项目名称:Ninja-Framework,代码行数:41,代码来源:view.php


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