public static function realJavaUpload($frontEnd = 0) { $app = JFactory::getApplication(); JRequest::checkToken('request') or exit('ERROR: ' . JText::_('COM_PHOCAGALLERY_INVALID_TOKEN')); // $files = JRequest::getVar( 'Filedata', '', 'files', 'array' ); $path = PhocaGalleryPath::getPath(); $folder = JRequest::getVar('folder', '', '', 'path'); if (isset($folder) && $folder != '') { $folder = $folder . DS; } $errUploadMsg = ''; $ftp = JClientHelper::setCredentialsFromRequest('ftp'); foreach ($_FILES as $fileValue => $file) { echo 'File key: ' . $fileValue . "\n"; foreach ($file as $item => $val) { echo ' Data received: ' . $item . '=>' . $val . "\n"; } // Make the filename safe if (isset($file['name'])) { $file['name'] = JFile::makeSafe($file['name']); } if (isset($file['name'])) { $filepath = JPath::clean($path->image_abs . $folder . strtolower($file['name'])); if (!PhocaGalleryFileUpload::canUpload($file, $errUploadMsg, $frontEnd)) { exit('ERROR: ' . JText::_($errUploadMsg)); } if (JFile::exists($filepath)) { exit('ERROR: ' . JText::_('COM_PHOCAGALLERY_FILE_ALREADY_EXISTS')); } if (!JFile::upload($file['tmp_name'], $filepath)) { exit('ERROR: ' . JText::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE')); } if ((int) $frontEnd > 0) { return $file['name']; } exit('SUCCESS'); } else { exit('ERROR: ' . JText::_('COM_PHOCAGALLERY_ERROR_UNABLE_TO_UPLOAD_FILE')); } } return true; }
function _singleFileUploadAvatar(&$errUploadMsg, $file, &$redirectUrl) { $app = JFactory::getApplication(); JRequest::checkToken('request') or jexit('Invalid Token'); jimport('joomla.client.helper'); $ftp =& JClientHelper::setCredentialsFromRequest('ftp'); $path = PhocaGalleryPath::getPath(); $format = JRequest::getVar('format', 'html', '', 'cmd'); $return = JRequest::getVar('return-url', null, 'post', 'base64'); $viewBack = JRequest::getVar('viewback', '', '', ''); $view = JRequest::getVar('view', '', 'get', '', JREQUEST_NOTRIM); $paramsC = JComponentHelper::getParams('com_phocagallery'); $limitStartUrl = $this->getLimitStartUrl(0, 'subcat'); $return = JRoute::_($this->_url . $limitStartUrl->subcat . $limitStartUrl->image, false); $enableUploadAvatar = (int) $paramsC->get('enable_upload_avatar', 1); if ($enableUploadAvatar != 1) { $errUploadMsg = JText::_('COM_PHOCAGALLERY_NOT_ABLE_UPLOAD_AVATAR'); $redirectUrl = $return; return false; } if (isset($file['name'])) { $fileAvatar = md5(uniqid(time())) . '.' . JFile::getExt($file['name']); $filepath = JPath::clean($path->avatar_abs . DS . $fileAvatar); if (!PhocaGalleryFileUpload::canUpload($file, $errUploadMsg)) { if ($errUploadMsg == 'COM_PHOCAGALLERY_WARNING_FILE_TOOLARGE') { $errUploadMsg = JText::_($errUploadMsg) . ' (' . PhocaGalleryFile::getFileSizeReadable($file['size']) . ')'; } else { if ($errUploadMsg == 'COM_PHOCAGALLERY_WARNING_FILE_TOOLARGERESOLUTION') { $imgSize = PhocaGalleryImage::getImageSize($file['tmp_name']); $errUploadMsg = JText::_($errUploadMsg) . ' (' . (int) $imgSize[0] . ' x ' . (int) $imgSize[1] . ' px)'; } else { $errUploadMsg = JText::_($errUploadMsg); } } $redirectUrl = $return; return false; } if (!JFile::upload($file['tmp_name'], $filepath)) { $errUploadMsg = JText::_('COM_PHOCAGALLERY_FILE_UNABLE_UPLOAD'); $redirectUrl = $return; return false; } else { $redirectUrl = $return; //Create thumbnail small, medium, large (Delete previous before) PhocaGalleryFileThumbnail::deleteFileThumbnail('avatars/' . $fileAvatar, 1, 1, 1); $returnFrontMessage = PhocaGalleryFileThumbnail::getOrCreateThumbnail('avatars/' . $fileAvatar, $return, 1, 1, 1, 1); if ($returnFrontMessage != 'Success') { $errUploadMsg = JText::_('COM_PHOCAGALLERY_THUMBNAIL_AVATAR_NOT_CREATED'); return false; } // Saving file name into database with relative path $succeeded = false; PhocaGalleryControllerUser::saveUser($fileAvatar, $succeeded, $errUploadMsg); $redirectUrl = $return; return $succeeded; } } else { $errUploadMsg = JText::_('COM_PHOCAGALLERY_WARNING_FILETYPE'); $redirectUrl = $return; return false; } return false; }