public static function realSingleUpload($frontEnd = 0)
{
$app = Factory::getApplication();
Session::checkToken('request') or jexit('ERROR: ' . Text::_('COM_PHOCAGALLERY_INVALID_TOKEN'));
$app->allowCache(false);
$path = PhocaGalleryPath::getPath();
$file = Factory::getApplication()->input->files->get('Filedata', null);
$folder = Factory::getApplication()->input->get('folder', '', '', 'path');
$format = Factory::getApplication()->input->get('format', 'html', '', 'cmd');
$return = JFactory::getApplication()->input->get('return-url', null, 'post', 'base64');
$viewBack = Factory::getApplication()->input->get('viewback', '', '', '');
$tab = Factory::getApplication()->input->get('tab', '', '', 'string');
$field = Factory::getApplication()->input->get('field');
$errUploadMsg = '';
$folderUrl = $folder;
$tabUrl = '';
$component = Factory::getApplication()->input->get('option', '', '', 'string');
if ($component != '' && $frontEnd == 0) {
$componentUrl = 'index.php?option=' . $component;
} else {
$componentUrl = 'index.php';
}
if ($tab != '') {
$tabUrl = '&tab=' . (string) $tab;
}
$ftp = ClientHelper::setCredentialsFromRequest('ftp');
if (isset($file['name'])) {
$file['name'] = File::makeSafe($file['name']);
}
if (isset($folder) && $folder != '') {
$folder = $folder . '/';
}
if (isset($file['name'])) {
$filepath = Path::clean($path->image_abs . $folder . strtolower($file['name']));
if (!PhocaGalleryFileUpload::canUpload($file, $errUploadMsg, $frontEnd)) {
if ($errUploadMsg == 'COM_PHOCAGALLERY_WARNING_FILE_TOOLARGE') {
$errUploadMsg = Text::_($errUploadMsg) . ' (' . PhocaGalleryFile::getFileSizeReadable($file['size']) . ')';
} else {
if ($errUploadMsg == 'COM_PHOCAGALLERY_WARNING_FILE_TOOLARGE_RESOLUTION') {
$imgSize = PhocaGalleryImage::getImageSize($file['tmp_name']);
$errUploadMsg = Text::_($errUploadMsg) . ' (' . (int) $imgSize[0] . ' x ' . (int) $imgSize[1] . ' px)';
} else {
$errUploadMsg = Text::_($errUploadMsg);
}
}
if ($return) {
$app->enqueueMessage($errUploadMsg, 'error');
if ($frontEnd > 0) {
$app->redirect(base64_decode($return));
} else {
$app->redirect(base64_decode($return) . '&folder=' . $folderUrl);
}
exit;
} else {
$app->enqueueMessage($errUploadMsg, 'error');
$app->redirect($componentUrl);
exit;
}
}
if (File::exists($filepath)) {
if ($return) {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'), 'error');
$app->redirect(base64_decode($return) . '&folder=' . $folderUrl);
exit;
} else {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS'), 'error');
$app->redirect($componentUrl);
exit;
}
}
if (!File::upload($file['tmp_name'], $filepath, false, true)) {
if ($return) {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE'), 'error');
$app->redirect(base64_decode($return) . '&folder=' . $folderUrl);
exit;
} else {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE'), 'error');
$app->redirect($componentUrl);
exit;
}
} else {
if ((int) $frontEnd > 0) {
return $file['name'];
}
if ($return) {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_SUCCESS_FILE_UPLOAD'));
$app->redirect(base64_decode($return) . '&folder=' . $folderUrl);
exit;
} else {
$app->enqueueMessage(Text::_('COM_PHOCAGALLERY_SUCCESS_FILE_UPLOAD'));
$app->redirect($componentUrl);
exit;
}
}
} else {
$msg = Text::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE');
if ($return) {
$app->enqueueMessage($msg);
$app->redirect(base64_decode($return) . '&folder=' . $folderUrl);
exit;
} else {
switch ($viewBack) {
case 'phocagalleryi':
$app->enqueueMessage($msg, 'error');
$app->redirect('index.php?option=com_phocagallery&view=phocagalleryi&tmpl=component' . $tabUrl . '&folder=' . $folder . '&field=' . $field);
exit;
break;
case 'phocagallerym':
$app->enqueueMessage($msg, 'error');
$app->redirect('index.php?option=com_phocagallery&view=phocagallerym&layout=form&hidemainmenu=1' . $tabUrl . '&folder=' . $folder);
exit;
break;
default:
$app->enqueueMessage($msg, 'error');
$app->redirect('index.php?option=com_phocagallery');
exit;
break;
}
}
}
}