本文整理汇总了PHP中MediaHelper::canUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP MediaHelper::canUpload方法的具体用法?PHP MediaHelper::canUpload怎么用?PHP MediaHelper::canUpload使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MediaHelper
的用法示例。
在下文中一共展示了MediaHelper::canUpload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例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;
}
示例3: 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;
}
示例4: _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();
}
}
示例5: _uploadFile
function _uploadFile($varName, $overwrite = false)
{
$mainframe = JFactory::getApplication();
$file = JRequest::getVar($varName, '', 'files', 'array');
$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');
require_once JPATH_COMPONENT . DS . 'helpers' . DS . 'media.php';
// Make the filename safe
jimport('joomla.filesystem.file');
$file['name'] = JFile::makeSafe($file['name']);
if (isset($file['name'])) {
$filepath = JPath::clean(JPATH_SITE . DS . 'tmp' . DS . strtolower($file['name']));
$format = strtolower(JFile::getExt($file['name']));
$allowable = array('png');
$ignore = array();
if (!in_array($format, $allowable) && !in_array($format, $ignore)) {
JError::raiseNotice(100, JText::_('Error: File is a wrong type, please upload a png'));
return false;
}
if (!MediaHelper::canUpload($file, $err)) {
JError::raiseNotice(100, JText::_($err));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return));
}
return;
}
if (JFile::exists($filepath) && !$overwrite) {
JError::raiseNotice(100, JText::_('Error. File already exists'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return));
}
return;
}
if (!JFile::upload($file['tmp_name'], $filepath)) {
JError::raiseWarning(100, JText::_('Error. Unable to upload file'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return));
}
return;
} else {
$mainframe->enqueueMessage(JText::_('Upload complete'));
// REDIRECT
if ($return) {
$mainframe->redirect(base64_decode($return));
}
$params =& JComponentHelper::getParams('com_webmapplus');
$filepath = str_replace(JPATH_ROOT, "", $filepath);
$file_information = pathinfo($filepath);
return $file_information;
}
} else {
$mainframe->redirect('index.php', 'Invalid Request', 'error');
}
}
示例6: upload
/**
* Upload a file
*
* @return void
*
* @since 1.0.4
*/
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();
JLog::addLogger(array('text_file' => 'upload.error.php'), JLog::ALL, array('upload'));
// Get some data from the request
$file = $this->input->files->get('Filedata', '', 'array');
$folder = $this->input->get('folder', '', 'path');
// Instantiate the media helper
$mediaHelper = new JHelperMedia();
if ($_SERVER['CONTENT_LENGTH'] > $params->get('upload_maxsize', 0) * 1024 * 1024 || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('upload_max_filesize')) || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('post_max_size')) || $_SERVER['CONTENT_LENGTH'] > $mediaHelper->toBytes(ini_get('memory_limit'))) {
$response = array('status' => '0', 'error' => JText::_('COM_BWPOSTMAN_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)) {
JLog::add('Invalid: ' . $filepath . ': ' . $err, JLog::INFO, 'upload');
$response = array('status' => '0', 'error' => JText::_($err));
echo json_encode($response);
return;
}
// Trigger the onContentBeforeSave event.
JPluginHelper::importPlugin('content');
$object_file = new JObject($file);
$object_file->filepath = $filepath;
if (JFile::exists($object_file->filepath)) {
// File exists
JLog::add('File exists: ' . $object_file->filepath . ' by user_id ' . $user->id, JLog::INFO, 'upload');
$response = array('status' => '0', 'error' => JText::_('COM_BWPOSTMAN_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
JLog::add('Create not permitted: ' . $object_file->filepath . ' by user_id ' . $user->id, JLog::INFO, 'upload');
$response = array('status' => '0', 'error' => JText::_('COM_BWPOSTMAN_MEDIA_ERROR_CREATE_NOT_PERMITTED'));
echo json_encode($response);
return;
}
if (!JFile::upload($object_file->tmp_name, $object_file->filepath)) {
// Error in upload
JLog::add('Error on upload: ' . $object_file->filepath, JLog::INFO, 'upload');
$response = array('status' => '0', 'error' => JText::_('COM_BWPOSTMAN_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
echo json_encode($response);
return;
} else {
JLog::add($folder, JLog::INFO, 'upload');
$response = array('status' => '1', 'error' => JText::sprintf('COM_BWPOSTMAN_MEDIA_UPLOAD_COMPLETE', substr($object_file->filepath, strlen(COM_MEDIA_BASE))));
echo json_encode($response);
return;
}
} else {
$response = array('status' => '0', 'error' => JText::_('COM_BWPOSTMAN_MEDIA_ERROR_BAD_REQUEST'));
echo json_encode($response);
return;
}
}
示例7: 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;
}
}
示例8: upload
/**
* Upload one or more files
*
* @return boolean
*
* @since 1.5
*/
public function upload()
{
// Check for request forgeries
JSession::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
$params = JComponentHelper::getParams('com_media');
// Get some data from the request
$files = $this->input->files->get('Filedata', '', 'array');
$return = $this->input->post->get('return-url', null, 'base64');
$this->folder = $this->input->get('folder', '', 'path');
// Set the redirect
if ($return)
{
$this->setRedirect(base64_decode($return) . '&folder=' . $this->folder);
}
// Authorize the user
if (!$this->authoriseUser('create'))
{
return false;
}
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) && ((int) (ini_get('memory_limit')) != -1))
)
{
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
return false;
}
// Perform basic checks on file info before attempting anything
foreach ($files as &$file)
{
$file['name'] = JFile::makeSafe($file['name']);
$file['filepath'] = JPath::clean(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $this->folder, $file['name'])));
if ($file['error'] == 1)
{
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
return false;
}
if ($file['size'] > ($params->get('upload_maxsize', 0) * 1024 * 1024))
{
JError::raiseNotice(100, JText::_('COM_MEDIA_ERROR_WARNFILETOOLARGE'));
return false;
}
if (JFile::exists($file['filepath']))
{
// A file with this name already exists
JError::raiseWarning(100, JText::_('COM_MEDIA_ERROR_FILE_EXISTS'));
return false;
}
if (!isset($file['name']))
{
// No filename (after the name was cleaned by JFile::makeSafe)
$this->setRedirect('index.php', JText::_('COM_MEDIA_INVALID_REQUEST'), 'error');
return false;
}
}
// Set FTP credentials, if given
JClientHelper::setCredentialsFromRequest('ftp');
JPluginHelper::importPlugin('content');
$dispatcher = JEventDispatcher::getInstance();
foreach ($files as &$file)
{
// The request is valid
$err = null;
if (!MediaHelper::canUpload($file, $err))
{
// The file can't be upload
JError::raiseNotice(100, JText::_($err));
return false;
}
// Trigger the onContentBeforeSave event.
$object_file = new JObject($file);
$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;
}
//.........这里部分代码省略.........
示例9: _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));
}
示例10: upload
function upload()
{
global $mainframe;
$version = new JVersion();
$joomla = $version->getShortVersion();
if (substr($joomla, 0, 3) >= '1.6') {
$mainframe = JFactory::getApplication();
}
$fileArr = JRequest::getVar('Filedata', '', 'files', 'array');
$folder = JRequest::getVar('folder', '', '', 'path');
$format = JRequest::getVar('format', 'html', '', 'cmd');
$return = JRequest::getVar('return-url', null, 'post', 'base64');
$parentId = JRequest::getVar('parentId');
$err = null;
//------------------------------
// to get the image size from seeting table
$dealImageSize = EnmasseHelper::getDealImageSize();
if (!empty($dealImageSize)) {
$image_height = $dealImageSize->image_height;
$image_width = $dealImageSize->image_width;
} else {
$image_height = 252;
$image_width = 400;
}
for ($i = 0; $i < count($fileArr['name']); $i++) {
$file[$i]['name'] = $fileArr['name'][$i];
$file[$i]['type'] = $fileArr['type'][$i];
$file[$i]['tmp_name'] = $fileArr['tmp_name'][$i];
$file[$i]['error'] = $fileArr['error'][$i];
$file[$i]['size'] = $fileArr['size'][$i];
}
// Set FTP credentials, if given
jimport('joomla.client.helper');
JClientHelper::setCredentialsFromRequest('ftp');
// Make the filename safe
jimport('joomla.filesystem.file');
$random = rand();
for ($count = 0; $count < count($file); $count++) {
$file[$count]['name'] = JFile::makeSafe($file[$count]['name']);
if (isset($file[$count]['name'])) {
$filepath = JPath::clean(JPATH_SITE . DS . 'components' . DS . 'com_enmasse' . DS . 'upload' . DS . strtolower($random . '-' . $count . '-' . $file[$count]['name']));
$imagepath = JPath::clean('components' . DS . 'com_enmasse' . DS . 'upload' . DS . strtolower($random . '-' . $count . '-' . $file[$count]['name']));
$imagePathArr[$count] = $imagepath;
if (!MediaHelper::canUpload($file[$count], $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 . '&parentId=' . $parentId);
}
return;
}
}
$image = $file[$count]["name"];
$uploadedfile = $file[$count]['tmp_name'];
$filename = stripslashes($file[$count]['name']);
$extension = $this->getExtension($filename);
$extension = strtolower($extension);
$size = filesize($file[$count]['tmp_name']);
if ($extension == "jpg" || $extension == "jpeg") {
$uploadedfile = $file[$count]['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
} else {
if ($extension == "png") {
$uploadedfile = $file[$count]['tmp_name'];
$src = imagecreatefrompng($uploadedfile);
}
}
list($width, $height) = getimagesize($uploadedfile);
$newwidth = 60;
$newheight = $height / $width * $newwidth;
$tmp = imagecreatetruecolor($newwidth, $newheight);
$newwidth1 = $image_width;
$newheight1 = $image_height;
$tmp1 = imagecreatetruecolor($newwidth1, $newheight1);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagecopyresampled($tmp1, $src, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height);
$filename = $filepath;
$filename1 = $filepath;
imagejpeg($tmp, $filename, 100);
imagejpeg($tmp1, $filename1, 100);
imagedestroy($src);
imagedestroy($tmp);
imagedestroy($tmp1);
if ($count == count($file) - 1) {
$mainframe->redirect(base64_decode($return) . '&folder=' . urlencode(serialize($imagePathArr)) . '&parentId=' . $parentId);
}
} else {
$mainframe->redirect('index.php', 'Invalid Request', 'error');
}
}
//$mainframe->redirect(base64_decode($return).'&folder='.$imagepath.'&parentId='.$parentId);
}
示例11: 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;
}
}
示例12: 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;
}
}
示例13: 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;
}
}
示例14: uploadAction
/**
* Action to handle media upload
*
* @return void
*/
public function uploadAction()
{
if ($this->request->getMethod() != 'POST') {
return;
}
$params = JComponentHelper::getParams('com_media');
$file = JRequest::getVar('jsn-file-upload', '', 'files', 'array');
if (!class_exists('MediaHelper')) {
require_once JPATH_ADMINISTRATOR . '/components/com_media/helpers/media.php';
}
// Load com_media language
$this->language->load('com_media');
// The request is valid
$error = null;
// Make sure uploaded file is an image file
if (!preg_match('/\\.(jpg|png|gif|xcf|odg|bmp|jpeg|ico)$/', $file['name'])) {
throw new Exception(JText::_('COM_MEDIA_ERROR_WARNFILETYPE'));
}
// Do some additional checks
if (!MediaHelper::canUpload($file, $error)) {
throw new Exception(JText::_(empty($error) ? 'JSN_TPLFW_GENERAL_UPLOADED_FILE_TYPE_NOT_SUPPORTED' : $error));
}
$filepath = JPath::clean($this->_getPath() . '/' . JFile::makeSafe($file['name']));
if (!JFile::upload($file['tmp_name'], $filepath)) {
throw new Exception(JText::_('COM_MEDIA_ERROR_UNABLE_TO_UPLOAD_FILE'));
}
// Prepare image file path
$path = str_replace(DIRECTORY_SEPARATOR, '/', $filepath);
$path = substr($path, strlen($this->rootPath));
$this->setResponse(array('id' => md5($path), 'path' => $path));
}
示例15: upload
public function upload()
{
$app = JFactory::getApplication();
// load language fo component media
$lang = JFactory::getLanguage();
$lang->load('com_media');
$params = JComponentHelper::getParams('com_media');
require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_media' . DS . 'helpers' . DS . 'media.php';
define('COM_AUP_MEDIA_BASE', JPATH_ROOT . DS . 'components' . DS . 'com_alphauserpoints' . DS . 'assets' . DS . 'images' . DS . 'awards');
// Check for request forgeries
JRequest::checkToken('request') or jexit('Invalid Token');
$files = JFactory::getApplication()->input->files->get('Filedata', '', 'array');
$file = $files[0];
$folder = JFactory::getApplication()->input->get('folder', 'icon', 'path');
$format = JFactory::getApplication()->input->get('format', 'html', 'cmd');
$return = JFactory::getApplication()->input->get('return-url', null, '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_AUP_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) {
$this->setRedirect(base64_decode($return));
$this->redirect();
}
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) {
$this->setRedirect(base64_decode($return));
$this->redirect();
}
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) {
$this->setRedirect(base64_decode($return));
$this->redirect();
}
return;
}
} else {
if ($format == 'json') {
jimport('joomla.error.log');
$log = JLog::getInstance();
$log->addEntry(array('comment' => $folder));
jexit('Upload complete');
} else {
$app->enqueueMessage(JText::_('Upload complete'));
// REDIRECT
if ($return) {
$this->setRedirect(base64_decode($return));
$this->redirect();
}
return;
}
}
} else {
$this->setRedirect('index.php', 'Invalid Request', 'error');
$this->redirect();
}
}