本文整理汇总了PHP中MediaHelper类的典型用法代码示例。如果您正苦于以下问题:PHP MediaHelper类的具体用法?PHP MediaHelper怎么用?PHP MediaHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MediaHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getProperties
/**
* Return the file properties of a specific file
*
* @param string $filePath
*
* @return array
*/
public function getProperties($filePath)
{
$properties = array();
$info = @getimagesize($filePath);
$properties['width'] = @$info[0];
$properties['height'] = @$info[1];
$properties['type'] = @$info[2];
$properties['mime'] = @$info['mime'];
if ($info[0] > 60 || $info[1] > 60) {
$dimensions = MediaHelper::imageResize($info[0], $info[1], 60);
$properties['width_60'] = $dimensions[0];
$properties['height_60'] = $dimensions[1];
} else {
$properties['width_60'] = $properties['width'];
$properties['height_60'] = $properties['height'];
}
if ($info[0] > 16 || $info[1] > 16) {
$dimensions = MediaHelper::imageResize($info[0], $info[1], 16);
$properties['width_16'] = $dimensions[0];
$properties['height_16'] = $dimensions[1];
} else {
$properties['width_16'] = $properties['width'];
$properties['height_16'] = $properties['height'];
}
return $properties;
}
开发者ID:dgt41,项目名称:media-manager-improvement,代码行数:33,代码来源:image.php
示例2: 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
示例3: 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
示例4: 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
示例5: buildXmlElementResponse
/**
* @param form_persistentdocument_file $field
* @param DOMElement $fieldElm
* @param mixed $rawValue
* @return string
*/
public function buildXmlElementResponse($field, $fieldElm, $rawValue)
{
if (f_util_ArrayUtils::isNotEmpty($rawValue) && $rawValue['error'] == 0) {
$media = MediaHelper::addUploadedFile($rawValue['name'], $rawValue['tmp_name'], $field->getMediaFolder());
$mailValue = "<a href=\"" . MediaHelper::getUrl($media) . "\">" . $media->getLabel() . "</a>";
$fieldElm->setAttribute('mailValue', $mailValue);
return $media->getId();
}
return '';
}
开发者ID:RBSWebFactory,项目名称:modules.form,代码行数:16,代码来源:FileService.class.php
示例6: searchUser
public function searchUser()
{
try {
$email = $this->request->data('email');
if (!$email) {
throw new Exception('Email is required');
}
$user = $this->FinanceShare->findUserByEmail($email);
if (isset($user['User']['id']) && $user['User']['id'] === $this->currUserID) {
$user = [];
}
if (isset($user['UserMedia'])) {
$mediaHelper = new MediaHelper(new View());
$user['UserMedia']['url_img'] = $mediaHelper->imageUrl($user['UserMedia'], 'thumb50x50');
}
$this->set(compact('user'));
$this->set('_serialize', array('user'));
} catch (Exception $e) {
exit($e->getMessage());
}
}
开发者ID:nilBora,项目名称:konstruktor,代码行数:21,代码来源:FinanceShareController.php
示例7: _execute
public function _execute($context, $request)
{
$form = $request->getAttribute('form');
$this->setAttribute('form', $form);
$domDoc = new DOMDocument();
$fieldNames = array('creationdate' => f_Locale::translate('&modules.form.bo.actions.SendDate;'));
$query = f_persistentdocument_PersistentProvider::getInstance()->createQuery('modules_form/response')->add(Restrictions::eq('parentForm.id', $form->getId()))->addOrder(Order::desc('document_creationdate'));
if ($request->getAttribute('all') != 'all') {
$query->add(Restrictions::published());
}
$responses = $query->find();
$responsesAttribute = array();
foreach ($responses as $response) {
$domDoc->loadXML($response->getContents());
$xpath = new DOMXPath($domDoc);
$fieldList = $xpath->query('/response/field');
$fields = array('creationdate' => $response->getUICreationdate());
for ($i = 0; $i < $fieldList->length; $i++) {
$fieldNode = $fieldList->item($i);
$fieldName = $fieldNode->getAttribute('name');
$fieldLabel = $fieldNode->getAttribute('label');
$fieldType = $fieldNode->getAttribute('type');
$fieldValue = $fieldNode->nodeValue;
if ($fieldType == 'file') {
$fieldValue = intval($fieldNode->nodeValue);
if ($fieldValue > 0) {
$fieldValue = MediaHelper::getUrl($fieldValue);
} else {
$fieldValue = '';
}
} else {
if ($fieldType == 'list' && $fieldNode->hasAttribute('mailValue')) {
$fieldValue = $fieldNode->getAttribute('mailValue');
}
}
if (!isset($fieldNames[$fieldName])) {
$fieldNames[$fieldName] = $fieldLabel;
}
$fields[$fieldName] = $fieldValue;
}
$responsesAttribute[] = $fields;
}
$fileName = "export_formulaire_" . f_util_FileUtils::cleanFilename($form->getLabel()) . '_' . date('Ymd_His') . '.csv';
$options = new f_util_CSVUtils_export_options();
$options->separator = ";";
$csv = f_util_CSVUtils::export($fieldNames, $responsesAttribute, $options);
header("Content-type: text/comma-separated-values");
header('Content-length: ' . strlen($csv));
header('Content-disposition: attachment; filename="' . $fileName . '"');
echo $csv;
exit;
}
开发者ID:RBSWebFactory,项目名称:modules.form,代码行数:52,代码来源:ExportCsvView.class.php
示例8: 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
示例9: _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
示例10: defined
*/
// No direct access.
defined('_JEXEC') or die;
?>
<div class="item">
<a href="javascript:ImageManager.populateFields('<?php
echo $this->_tmp_img->path_relative;
?>
')">
<img src="<?php
echo $this->baseURL . '/' . $this->_tmp_img->path_relative;
?>
" width="<?php
echo $this->_tmp_img->width_60;
?>
" height="<?php
echo $this->_tmp_img->height_60;
?>
" alt="<?php
echo $this->_tmp_img->name;
?>
- <?php
echo MediaHelper::parseSize($this->_tmp_img->size);
?>
" />
<span><?php
echo $this->_tmp_img->name;
?>
</span></a>
</div>
开发者ID:joebushi,项目名称:joomla,代码行数:30,代码来源:default_image.php
示例11: upload
/**
* Upload a file
*
* @since 1.5
*/
function upload()
{
$params = JComponentHelper::getParams('com_media');
// Check for request forgeries
if (!JSession::checkToken('request')) {
$response = array('status' => '0', 'error' => JText::_('JINVALID_TOKEN'));
echo json_encode($response);
return;
}
// Get the user
$user = JFactory::getUser();
$log = JLog::getInstance('upload.error.php');
// Get some data from the request
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
if ($_SERVER['CONTENT_LENGTH'] > $params->get('upload_maxsize', 0) * 1024 * 1024 || $_SERVER['CONTENT_LENGTH'] > (int) ini_get('upload_max_filesize') * 1024 * 1024 || $_SERVER['CONTENT_LENGTH'] > (int) ini_get('post_max_size') * 1024 * 1024 || $_SERVER['CONTENT_LENGTH'] > (int) ini_get('memory_limit') * 1024 * 1024) {
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
echo json_encode($response);
return;
}
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
// The request is valid
$err = null;
$filepath = JPath::clean(COM_MEDIA_BASE . '/' . $folder . '/' . strtolower($file['name']));
if (!MediaHelper::canUpload($file, $err)) {
$log->addEntry(array('comment' => 'Invalid: ' . $filepath . ': ' . $err));
$response = array('status' => '0', 'error' => JText::_($err));
echo json_encode($response);
return;
}
// Trigger the onContentBeforeSave event.
JPluginHelper::importPlugin('content');
$dispatcher = JDispatcher::getInstance();
$object_file = new JObject($file);
$object_file->filepath = $filepath;
$result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file));
if (in_array(false, $result, true)) {
// There are some errors in the plugins
$log->addEntry(array('comment' => 'Errors before save: ' . $filepath . ' : ' . implode(', ', $object_file->getErrors())));
$response = array('status' => '0', 'error' => JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
echo json_encode($response);
return;
}
if (JFile::exists($filepath)) {
// File exists
$log->addEntry(array('comment' => 'File exists: ' . $filepath . ' by user_id ' . $user->id));
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_FILE_EXISTS'));
echo json_encode($response);
return;
} elseif (!$user->authorise('core.create', 'com_media')) {
// File does not exist and user is not authorised to create
$log->addEntry(array('comment' => 'Create not permitted: ' . $filepath . ' by user_id ' . $user->id));
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
echo json_encode($response);
return;
}
$file = (array) $object_file;
if (!JFile::upload($file['tmp_name'], $file['filepath'])) {
// Error in upload
$log->addEntry(array('comment' => 'Error on upload: ' . $filepath));
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
echo json_encode($response);
return;
} else {
// Trigger the onContentAfterSave event.
$dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true));
$log->addEntry(array('comment' => $folder));
$response = array('status' => '1', 'error' => JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE))));
echo json_encode($response);
return;
}
} else {
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_BAD_REQUEST'));
echo json_encode($response);
return;
}
}
开发者ID:laiello,项目名称:senluonirvana,代码行数:87,代码来源:file.json.php
示例12:
?>
<div class="imgOutline">
<div class="imgTotal">
<div class="imgBorder center">
<a class="img-preview" href="<?php
echo COM_MEDIA_BASEURL . '/' . $this->_tmp_img->path_relative;
?>
" title="<?php
echo $this->_tmp_img->name;
?>
" style="display: block; width: 100%; height: 100%">
<img src="<?php
echo COM_MEDIA_BASEURL . '/' . $this->_tmp_img->path_relative;
?>
" alt="<?php
echo Lang::txt('COM_MEDIA_IMAGE_TITLE', $this->_tmp_img->title, MediaHelper::parseSize($this->_tmp_img->size));
?>
" width="<?php
echo $this->_tmp_img->width_60;
?>
" height="<?php
echo $this->_tmp_img->height_60;
?>
" />
</a>
</div>
</div>
<div class="controls">
<?php
if (User::authorise('core.delete', 'com_media')) {
?>
开发者ID:mined-gatech,项目名称:hubzero-cms,代码行数:31,代码来源:thumbs_img.php
示例13: upload
/**
* Upload a file
* @return void
* @since 1.5
*/
function upload()
{
return;
// Check for request forgeries
if (!JRequest::checkToken('request')) {
$response = array('status' => '0', 'error' => JText::_('JINVALID_TOKEN'));
echo json_encode($response);
return;
}
// Get the user
$user = JFactory::getUser();
// Get some data from the request
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
// The request is valid
$err = null;
$filepath = JPath::clean(JPATH_COMPONENT . DS . $folder . DS . strtolower($file['name']));
if (!MediaHelper::canUpload($file, $err)) {
$response = array('status' => '0', 'error' => JText::_($err));
echo json_encode($response);
return;
}
// Trigger the onContentBeforeSave event.
JPluginHelper::importPlugin('content');
$dispatcher = JDispatcher::getInstance();
$object_file = new JObject($file);
$object_file->filepath = $filepath;
$result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', $object_file));
if (in_array(false, $result, true)) {
// There are some errors in the plugins
$log->addEntry(array('comment' => 'Errors before save: ' . $filepath . ' : ' . implode(', ', $object_file->getErrors())));
$response = array('status' => '0', 'error' => JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
echo json_encode($response);
return;
}
if (JFile::exists($filepath)) {
// File exists
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_FILE_EXISTS'));
echo json_encode($response);
return;
} elseif (!$user->authorise('core.create', 'com_media')) {
// File does not exist and user is not authorised to create
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
echo json_encode($response);
return;
}
$file = (array) $object_file;
if (!JFile::upload($file['tmp_name'], $file['filepath'])) {
// Error in upload
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
echo json_encode($response);
return;
} else {
// Trigger the onContentAfterSave event.
//$dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file), null);
$response = array('status' => '1', 'error' => JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen('COM_MEDIA_BASE'))));
echo json_encode($response);
return;
}
} else {
$response = array('status' => '0', 'error' => JText::_('COM_MEDIA_ERROR_BAD_REQUEST'));
echo json_encode($response);
return;
}
}
开发者ID:Rikisha,项目名称:proj,代码行数:77,代码来源:file.json.php
示例14: upload
/**
* Upload a file
*
* @since 1.5
*/
function upload()
{
global $mainframe;
// Check for request forgeries
JRequest::checkToken('request') or jexit('Invalid Token');
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$format = JRequest::getVar('format', 'html', '', 'cmd');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
$err = null;
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
$filepath = JPath::clean(COM_MEDIA_BASE . DS . $folder . DS . strtolower($file['name']));
if (!MediaHelper::canUpload($file, $err)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Invalid: ' . $filepath . ': ' . $err));
header('HTTP/1.0 415 Unsupported Media Type');
jexit('Error. Unsupported Media Type!');
} else {
JError::raiseNotice(100, JText::_($err));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return) . '&folder=' . $folder);
}
return;
}
}
if (JFile::exists($filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'File already exists: ' . $filepath));
header('HTTP/1.0 409 Conflict');
jexit('Error. File already exists');
} else {
JError::raiseNotice(100, JText::_('Error. File already exists'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return) . '&folder=' . $folder);
}
return;
}
}
if (!JFile::upload($file['tmp_name'], $filepath)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Cannot upload: ' . $filepath));
header('HTTP/1.0 400 Bad Request');
jexit('Error. Unable to upload file');
} else {
JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return) . '&folder=' . $folder);
}
return;
}
} else {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance();
$log->addEntry(array('comment' => $folder));
jexit('Upload complete');
} else {
$mainframe->enqueueMessage(JText::_('Upload complete'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return) . '&folder=' . $folder);
}
return;
}
}
} else {
$mainframe->redirect('index.php', 'Invalid Request', 'error');
}
}
开发者ID:RangerWalt,项目名称:ecci,代码行数:89,代码来源:file.php
示例15: defined
* @subpackage com_media
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access.
defined('_JEXEC') or die;
$params = new JRegistry();
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('onContentBeforeDisplay', array('com_media.file', &$this->_tmp_img, &$params));
?>
<div class="item">
<a href="javascript:ImageManager.populateFields('<?php
echo $this->_tmp_img->path_relative;
?>
')" title="<?php
echo $this->_tmp_img->name;
?>
" >
<?php
echo JHtml::_('image', $this->baseURL . '/' . $this->_tmp_img->path_relative, JText::sprintf('COM_MEDIA_IMAGE_TITLE', $this->_tmp_img->title, MediaHelper::parseSize($this->_tmp_img->size)), array('width' => $this->_tmp_img->width_60, 'height' => $this->_tmp_img->height_60));
?>
<span title="<?php
echo $this->_tmp_img->name;
?>
"><?php
echo $this->_tmp_img->title;
?>
</span></a>
</div>
<?php
$dispatcher->trigger('onContentAfterDisplay', array('com_media.file', &$this->_tmp_img, &$params));
开发者ID:acculitx,项目名称:fleetmatrixsite,代码行数:31,代码来源:default_image.php
示例16: uploadFile
protected function uploadFile($file, $checkUpload = true)
{
if (isset($file['name'])) {
JLoader::import('joomla.filesystem.file');
// Can we upload this file type?
if ($checkUpload) {
if (!class_exists('MediaHelper')) {
require_once JPATH_ADMINISTRATOR . '/components/com_media/helpers/media.php';
}
$err = '';
$paths = array(JPATH_ROOT, JPATH_ADMINISTRATOR);
$jlang = JFactory::getLanguage();
$jlang->load('com_media', $paths[0], 'en-GB', true);
$jlang->load('com_media', $paths[0], null, true);
$jlang->load('com_media', $paths[1], 'en-GB', true);
$jlang->load('com_media', $paths[1], null, true);
if (!MediaHelper::canUpload($file, $err)) {
if (!empty($err)) {
$err = JText::_($err);
} else {
$app = JFactory::getApplication();
$errors = $app->getMessageQueue();
if (count($errors)) {
$error = array_pop($errors);
$err = $error['message'];
} else {
$err = '';
}
}
$content = file_get_contents($file['tmp_name']);
if (preg_match('/\\<\\?php/i', $content)) {
$err = JText::_('J2STORE_UPLOAD_FILE_PHP_TAGS');
}
if (!empty($err)) {
$this->setError(JText::_('J2STORE_UPLOAD_ERR_MEDIAHELPER_ERROR') . ' ' . $err);
} else {
$this->setError(JText::_('J2STORE_UPLOAD_ERR_GENERIC_ERROR'));
}
return false;
}
}
// Get a (very!) randomised name
$serverkey = JFactory::getConfig()->get('secret', '');
$sig = $file['name'] . microtime() . $serverkey;
if (function_exists('sha256')) {
$mangledname = sha256($sig);
} elseif (function_exists('sha1')) {
$mangledname = sha1($sig);
} else {
$mangledname = md5($sig);
}
$upload_folder_path = JPATH_ROOT . '/media/j2store/uploads';
if (!JFolder::exists($upload_folder_path)) {
if (!JFolder::create($upload_folder_path)) {
$this->setError(JText::_('J2STORE_UPLOAD_ERROR_FOLDER_PERMISSION_ERROR'));
}
}
//sanitize file name
$filename = basename(preg_replace('/[^a-zA-Z0-9\\.\\-\\s+]/', '', html_entity_decode($file['name'], ENT_QUOTES, 'UTF-8')));
$name = $filename . '.' . md5(mt_rand());
// ...and its full path
$filepath = JPath::clean(JPATH_ROOT . '/media/j2store/uploads/' . $name);
// If we have a name clash, abort the upload
if (JFile::exists($filepath)) {
$this->setError(JText::_('J2STORE_UPLOAD_ERR_NAMECLASH'));
return false;
}
// Do the upload
if ($checkUpload) {
if (!JFile::upload($file['tmp_name'], $filepath)) {
$this->setError(JText::_('J2STORE_UPLOAD_ERR_CANTJFILEUPLOAD'));
return false;
}
} else {
if (!JFile::copy($file['tmp_name'], $filepath)) {
$this->setError(JText::_('J2STORE_UPLOAD_ERR_CANTJFILEUPLOAD'));
return false;
}
}
// Get the MIME type
if (function_exists('mime_content_type')) {
$mime = mime_content_type($filepath);
} elseif (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $filepath);
} else {
$mime = 'application/octet-stream';
}
// Return the file info
return array('original_name' => $file['name'], 'mangled_name' => $mangledname, 'saved_name' => $name, 'mime_type' => $mime);
} else {
$this->setError(JText::_('J2STORE_ATTACHMENTS_ERR_NOFILE'));
return false;
}
}
开发者ID:davetheapple,项目名称:oakencraft,代码行数:95,代码来源:carts.php
示例17: upload
/**
* Upload a file
*
* @since 1.5
*/
function upload()
{
// Check for request forgeries
JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
// Get the user
$user = JFactory::getUser();
// Get some data from the request
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
// Set the redirect
if ($return) {
$this->setRedirect(base64_decode($return) . '&folder=' . $folder);
}
// Make the filename safe
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
// The request is valid
$err = null;
if (!MediaHelper::canUpload($file, $err)) {
// The file can't be upload
JError::raiseNotice(100, JText::_($err));
return false;
}
$filepath = JPath::clean(COM_MEDIA_BASE . '/' . $folder . '/' . strtolower($file['name']));
// Trigger the onContentBeforeSave event.
JPluginHelper::importPlugin('content');
$dispatcher = JDispatcher::getInstance();
$object_file = new JObject($file);
$object_file->filepath = $filepath;
$result = $dispatcher->trigger('onContentBeforeSave', array('com_media.file', &$object_file));
if (in_array(false, $result, true)) {
// There are some errors in the plugins
JError::raiseWarning(100, JText::plural('COM_MEDIA_ERROR_BEFORE_SAVE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
return false;
}
$file = (array) $object_file;
if (JFile::exists($file['filepath'])) {
// File exists
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS'));
return false;
} elseif (!$user->authorise('core.create', 'com_media')) {
// File does not exist and user is not authorised to create
JError::raiseWarning(403, JText::_('COM_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
return false;
}
if (!JFile::upload($file['tmp_name'], $file['filepath'])) {
// Error in upload
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
return false;
} else {
// Trigger the onContentAfterSave event.
$dispatcher->trigger('onContentAfterSave', array('com_media.file', &$object_file, true));
$this->setMessage(JText::sprintf('COM_MEDIA_UPLOAD_COMPLETE', substr($file['filepath'], strlen(COM_MEDIA_BASE))));
return true;
}
} else {
$this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error');
return false;
}
}
开发者ID:salomalo,项目名称:nbs-01,代码行数:68,代码来源:file.php
示例18: uploadranks
function uploadranks()
{
$kunena_config = KunenaFactory::getConfig();
$kunena_app =& JFactory::getApplication();
// load language fo component media
JPlugin::loadLanguage('com_media');
$params =& JComponentHelper::getParams('com_media');
require_once JPATH_ADMINISTRATOR . '/components/com_media/helpers/media.php';
define('COM_KUNENA_MEDIA_BASE', JPATH_ROOT . '/components/com_kunena/template/' . $kunena_config->template . '/images');
// Check for request forgeries
JRequest::checkToken('request') or jexit('Invalid Token');
$file = JRequest::getVar('Filedata', '', 'files', 'array');
$folderranks = JRequest::getVar('folderranks', 'ranks', '', 'path');
$format = JRequest::getVar('format', 'html', '', 'cmd');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
$err = null;
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
$filepathranks = JPath::clean(COM_KUNENA_MEDIA_BASE . '/' . $folderranks . '/' . strtolower($file['name']));
if (!MediaHelper::canUpload($file, $err)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Invalid: ' . $filepathranks . ': ' . $err));
header('HTTP/1.0 415 Unsupported Media Type');
jexit('Error. Unsupported Media Type!');
} else {
JError::raiseNotice(100, JText::_($err));
// REDIRECT
if ($return) {
while (@ob_end_clean()) {
}
$kunena_app->redirect(base64_decode($return));
}
return;
}
}
if (JFile::exists($filepathranks)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'File already exists: ' . $filepathranks));
header('HTTP/1.0 409 Conflict');
jexit('Error. File already exists');
} else {
JError::raiseNotice(100, JText::_('COM_KUNENA_A_RANKS_UPLOAD_ERROR_EXIST'));
// REDIRECT
if ($return) {
while (@ob_end_clean()) {
}
$kunena_app->redirect(base64_decode($return));
}
return;
}
}
if (!JFile::upload($file['tmp_name'], $filepathranks)) {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance('upload.error.php');
$log->addEntry(array('comment' => 'Cannot upload: ' . $filepathranks));
header('HTTP/1.0 400 Bad Request');
jexit('Error. Unable to upload file');
} else {
JError::raiseWarning(100, JText::_('COM_KUNENA_A_RANKS_UPLOAD_ERROR_UNABLE'));
// REDIRECT
if ($return) {
while (@ob_end_clean()) {
}
$kunena_app->redirect(base64_decode($return));
}
return;
}
} else {
if ($format == 'json') {
jimport('joomla.error.log');
$log =& JLog::getInstance();
$log->addEntry(array('comment' => $filepathranks));
jexit('Upload complete');
} else {
$kunena_app->enqueueMessage(JText::_('COM_KUNENA_A_RANKS_UPLOAD_SUCCESS'));
// REDIRECT
if ($return) {
while (@ob_end_clean()) {
}
$kunena_app->redirect(base64_decode($return));
}
return;
}
}
} else {
while (@ob_end_clean()) {
}
$kunena_app->redirect('index.php', 'Invalid Request', 'error');
}
}
开发者ID:vuchannguyen,项目名称:hoctap,< |
请发表评论