/** * logic for uploading an image * * @access public * @return void * @since 0.9 */ function upload() { $mainframe = JFactory::getApplication(); $option = JRequest::getCmd('option'); // Check for request forgeries JRequest::checkToken() or die('Invalid Token'); $file = JRequest::getVar('userfile', '', 'files', 'array'); //$task = JRequest::getVar( 'task' ); $type = JRequest::getVar('type'); $folder = ImageSelect::getfolder($type); // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); //$ftp = JClientHelper::getCredentials('ftp'); //set the target directory $base_Dir = JPATH_SITE . '/' . 'media' . '/' . 'com_tracks' . '/' . 'images' . '/' . $folder . '/'; //do we have an upload? if (empty($file['name'])) { echo "<script> alert('" . JText::_('COM_TRACKS_IMAGE_EMPTY') . "'); window.history.go(-1); </script>\n"; $mainframe->close(); } //check the image $check = ImageSelect::check($file); if ($check === false) { $mainframe->redirect($_SERVER['HTTP_REFERER']); } //sanitize the image filename $filename = ImageSelect::sanitize($base_Dir, $file['name']); $filepath = $base_Dir . $filename; //upload the image if (!JFile::upload($file['tmp_name'], $filepath)) { echo "<script> alert('" . JText::_('COM_TRACKS_UPLOAD_FAILED') . "'); window.history.go(-1); </script>\n"; $mainframe->close(); } else { echo "<script> alert('" . JText::_('COM_TRACKS_UPLOAD_COMPLETE') . "'); window.history.go(-1); window.parent.elSelectImage('{$filename}', '{$filename}'); </script>\n"; $mainframe->close(); } }
/** * Method to store the individual data * * @access public * @return boolean True on success * @since 1.5 */ function store($data, $picture, $picture_small) { // Require the base controller require_once JPATH_COMPONENT_ADMINISTRATOR . '/' . 'tables' . '/' . 'individual.php'; $table = $this->getTable('individual'); $params = JComponentHelper::getParams('com_tracks'); $user = JFactory::getUser(); $username = $user->get('username'); if ($data['id']) { $table->load($data['id']); if ($table->user_id != $user->get('id') && !$user->authorise('core.manage', 'com_tracks')) { JError::raiseError(403, JText::_('COM_TRACKS_ACCESS_NOT_ALLOWED')); } } // Bind the form fields to the user table if (!$table->bind($data)) { $this->setError($this->_db->getErrorMsg()); return false; } $targetpath = 'images' . '/' . $params->get('default_individual_images_folder', 'tracks/individuals'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); if (!empty($picture['name'])) { $base_Dir = JPATH_SITE . '/' . $targetpath . '/'; if (!JFolder::exists($base_Dir)) { JFolder::create($base_Dir); } //check the image $check = ImageSelect::check($picture); if ($check === false) { $this->setError('IMAGE CHECK FAILED'); return false; } //sanitize the image filename $filename = ImageSelect::sanitize($base_Dir, $picture['name']); $filepath = $base_Dir . $filename; //dump($filepath); if (!JFile::upload($picture['tmp_name'], $filepath)) { $this->setError(JText::_('COM_TRACKS_UPLOAD_FAILED')); return false; } else { $table->picture = $targetpath . '/' . $filename; } } else { //keep image if edited and left blank unset($table->picture); } //end image upload if if (!empty($picture_small['name'])) { jimport('joomla.filesystem.file'); $base_Dir = JPATH_SITE . '/' . $targetpath . '/' . 'small' . '/'; if (!JFolder::exists($base_Dir)) { JFolder::create($base_Dir); } //check the image $check = ImageSelect::check($picture_small); if ($check === false) { $this->setError('IMAGE CHECK FAILED'); return false; } //sanitize the image filename $filename = ImageSelect::sanitize($base_Dir, $picture_small['name']); $filepath = $base_Dir . $filename; if (!JFile::upload($picture_small['tmp_name'], $filepath)) { $this->setError(JText::_('COM_TRACKS_UPLOAD_FAILED')); return false; } else { $table->picture_small = $targetpath . '/' . 'small' . '/' . $filename; } } else { //keep image if edited and left blank unset($table->picture_small); } //end image upload if // Store the individual to the database if (!$table->save($data)) { $this->setError($user->getError()); return false; } $this->id = $table->id; return $this->id; }