Example #1
0
 public function getData()
 {
     ob_clean();
     $app = JFactory::getApplication();
     $session = JFactory::getSession();
     $post = JRequest::get('post');
     $files = JRequest::get('files');
     $files = $files[$post['task'] . $post['import']];
     if (isset($post['task']) && isset($post['import'])) {
         if ($files['name'] == "") {
             return JText::_('PLEASE_SELECT_FILE');
         }
         $ext = strtolower(JFile::getExt($files['name']));
         if ($ext != 'csv') {
             return JText::_('FILE_EXTENSION_WRONG');
         }
     } else {
         if (!isset($post['import'])) {
             return JText::_('PLEASE_SELECT_SECTION');
         }
     }
     // Upload csv file
     $src = $files['tmp_name'];
     $dest = JPATH_ROOT . '/components/com_redshop/assets/importcsv/' . $post['import'] . '/' . $files['name'];
     $file_upload = JFile::upload($src, $dest);
     $session->clear('ImportPost');
     $session->clear('Importfile');
     $session->clear('Importfilename');
     $session->set('ImportPost', $post);
     $session->set('Importfile', $files);
     $session->set('Importfilename', $files['name']);
     $app->Redirect('index.php?option=com_redshop&view=import&layout=importlog');
     return;
 }
Example #2
0
 function upload($file)
 {
     $uploadPath = JPATH_ROOT . DS . 'images' . DS . 'phocagallery' . DS . 'tabla' . DS . $file['name'];
     if (!JFile::upload($file['tmp_name'], $uploadPath)) {
         return False;
     }
 }
Example #3
0
 public function subir()
 {
     $jinput = JFactory::getApplication()->input;
     /**
      * Esta tarea debe accionarse sólamente cuándo el artículo ha sido previamente guardado,
      * con el fin de evitar subir archivos huerfanos
      */
     $id = $jinput->get->get('id', null, null);
     if ($id == 0) {
         print_r('Debe haber guardado el artículo para agregar adjuntos');
         return;
     }
     // Obtiene la variable @campo enviada en el request
     $campo = $jinput->get->get('campo', null, null);
     $archivo = $jinput->files->get($campo);
     if (isset($archivo)) {
         // Sanea el nombre de archivo evitando caracteres no deseados
         $nombreArchivo = strtolower(JFile::makeSafe($archivo['name']));
         // Define el origen y destino del archivo
         // TODO: Crear directorio propio para los adjuntos del artículo
         // y usarlo como path destino.
         $src = $archivo['tmp_name'];
         $dest = JPATH_ROOT . DS . 'uploads' . DS . sha1(time()) . '-' . $nombreArchivo;
         if (JFile::upload($src, $dest)) {
             // TODO: Implementa/valida una estructura de datos para los nombres
             // de los archivos que se guardan en la base de datos
             print_r("Archivo Subido");
         } else {
             print_r("Ha ocurrido un error");
             print_r($archivo['error']);
         }
     }
 }
 function upload($file, $path, $override = 0)
 {
     //Import filesystem libraries. Perhaps not necessary, but does not hurt
     jimport('joomla.filesystem.file');
     //Clean up filename to get rid of strange characters like spaces etc
     $filename = JFile::makeSafe($file['name']);
     $filename = str_replace(' ', '-', $filename);
     //Set up the source and destination of the file
     $src = $file['tmp_name'];
     $dest = $path . $filename;
     //First check if the file has the right extension, we need jpg only
     $ext = strtolower(JFile::getExt($filename));
     if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg') {
         //check exits
         if (!$override) {
             if (JFile::exists($dest)) {
                 echo "<script> alert('Image {$filename} exists on server');\r\n\t\t\t\t\t\twindow.history.go(-1); </script>\n";
                 exit;
             }
         }
         if (JFile::upload($src, $dest)) {
             return $filename;
         } else {
             echo "<script> alert('Error upload image');\r\n\t\t\twindow.history.go(-1); </script>\n";
             exit;
         }
     } else {
         echo "<script> alert('Chi cho phep cac loai anh: jpg, gif, png');\r\n\t\t\twindow.history.go(-1); </script>\n";
         exit;
     }
     return false;
 }
Example #5
0
 /**
  * Receives H5P upload requests from views/h5p/tmpl/upload.php
  */
 public function upload()
 {
     $destination_folder = JFactory::getConfig()->get('tmp_path') . DIRECTORY_SEPARATOR . uniqid('h5ptmp-');
     $destination_path = $destination_folder . DIRECTORY_SEPARATOR . $_FILES['h5p']['name'];
     $tmp_name = $_FILES['h5p']['tmp_name'];
     if (!$tmp_name || !JFile::upload($tmp_name, $destination_path, FALSE)) {
         H5PJoomla::setErrorMessage('Not able to upload the given file.');
         print "\n\t\t\t\t<p>Unable to upload file. Is the file larger than the allowed file transfer size of the server?</p>\n\t\t\t\t<p><a href=\"javascript:window.history.back();\">Try again.</a></p>\n\t\t\t";
         return;
     }
     $_SESSION['h5p_upload'] = $destination_path;
     $_SESSION['h5p_upload_folder'] = $destination_folder;
     $h5p_validator = H5PJoomla::getInstance('validator');
     $valid = $h5p_validator->isValidPackage();
     if (!$valid) {
         H5PJoomla::setErrorMessage('The uploaded file was not a valid h5p package');
         print "\n\t\t\t\t<p>Uploaded file did not validate as a proper H5P. See errors above for further explanation.</p>\n\t\t\t\t<p><a href=\"javascript:window.history.back();\">Try again.</a></p>\n\t\t\t";
         return;
     }
     $h5p_storage = H5PJoomla::getInstance('storage');
     $uid = uniqid('h5p-', true);
     // uniqid is not quite UUID, but good enough here.
     $library_updated = $h5p_storage->savePackage($uid);
     $title = isset($_REQUEST['new-h5p-title']) ? $_REQUEST['new-h5p-title'] : "Untitled H5P upload";
     // Response HTML
     $document = JFactory::getDocument();
     $document->setMimeEncoding('text/html');
     print "\n\t\t\t<script type=\"text/javascript\">\n\t\t\t\twindow.parent.insertH5P('{$uid}', '{$title}');\n\t\t\t</script>\n\t\t";
 }
 function getPackageFromUpload()
 {
     $install_file = JRequest::getVar('package', null, 'files', 'array');
     if (!(bool) ini_get('file_uploads')) {
         $msg = 'File upload function is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (!extension_loaded('zlib')) {
         $msg = 'Zlib library is disabled, please enable it in file "php.ini"';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if ($install_file['name'] == '') {
         $msg = 'The package is not selected, please download and select it';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     if (JFile::getExt($install_file['name']) != 'zip') {
         $msg = 'The package has incorrect format, please use exactly the file you downloaded';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $tmp_dest = JPATH_ROOT . DS . 'tmp' . DS . $install_file['name'];
     $tmp_src = $install_file['tmp_name'];
     if (!JFile::upload($tmp_src, $tmp_dest)) {
         $msg = 'Folder "tmp" is Unwritable, please set it to Writable (chmod 777). You can set the folder back to Unwritable after sample data installation';
         JError::raiseWarning('SOME_ERROR_CODE', JText::_($msg));
         return false;
     }
     $package = JInstallerHelper::unpack($tmp_dest);
     return $package;
 }
Example #7
0
 /**
  * Upload files and attach them to an issue or a comment.
  *
  * @param   array  $files      Array containing the uploaded files.
  * @param   int    $issueId    ID of the issue/comment where to attach the files.
  * @param   int    $commentId  One of 'issue' or 'comment', indicating if the files should be attached to an issue or a comment.
  *
  * @return  boolean   True on success, false otherwise.
  */
 public function upload($files, $issueId, $commentId = null)
 {
     if (!$issueId || !is_array($files)) {
         return false;
     }
     jimport('joomla.filesystem.file');
     if ($commentId) {
         $type = 'comment';
         $id = $commentId;
     } else {
         $type = 'issue';
         $id = $issueId;
     }
     foreach ($files as $file) {
         $rand = MonitorHelper::genRandHash();
         $pathParts = array($type, $id, $rand . '-' . $file[0]['name']);
         $path = JPath::clean(implode(DIRECTORY_SEPARATOR, $pathParts));
         $values = array('issue_id' => $issueId, 'comment_id' => $commentId, 'path' => $path, 'name' => $file[0]['name']);
         if (!JFile::upload($file[0]['tmp_name'], $this->pathPrefix . $path)) {
             JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_MONITOR_ATTACHMENT_UPLOAD_FAILED', $file[0]['name']));
             return false;
         }
         $query = $this->db->getQuery(true);
         $query->insert('#__monitor_attachments')->set(MonitorHelper::sqlValues($values, $query));
         $this->db->setQuery($query);
         if ($this->db->execute() === false) {
             return false;
         }
     }
     return true;
 }
Example #8
0
	/**
	 * checks uploaded file, and uploads it
	 * @return true csv file uploaded ok, false error (JErrir warning raised)
	 */

	function checkUpload()
	{
		if (!(bool)ini_get('file_uploads')) {
			JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
			return false;
		}
		$userfile = JRequest::getVar('jform', null, 'files');
		if (!$userfile) {
			JError::raiseWarning(500, JText::_('COM_FABRIK_IMPORT_CSV_NO_FILE_SELECTED'));
			return false;
		}
		jimport('joomla.filesystem.file');

		$to = JPath::clean(COM_FABRIK_BASE.'media'.DS.$userfile['name']['userfile']);

		$resultdir = JFile::upload($userfile['tmp_name']['userfile'], $to);
		if ($resultdir == false) {
			JError::raiseWarning(500, JText::_('Upload Error'));
			return false;
		}

		$allowed = array('txt', 'csv', 'tsv');
		if (!in_array(JFile::getExt($userfile['name']['userfile']), $allowed)) {
			JError::raiseError(500, 'File must be a csv file');
			return false;
		}
		return true;
	}
Example #9
0
 /**
  * Installs an Application from a user upload.
  *
  * @param array $userfile The userfile to install from
  * @return int 2 = update, 1 = install
  *
  * @throws InstallHelperException
  * @since 2.0
  */
 public function installApplicationFromUserfile($userfile)
 {
     // Make sure that file uploads are enabled in php
     if (!(bool) ini_get('file_uploads')) {
         throw new InstallHelperException('Fileuploads are not enabled in php.');
     }
     // If there is no uploaded file, we have a problem...
     if (!is_array($userfile)) {
         throw new InstallHelperException('No file selected.');
     }
     // Check if there was a problem uploading the file.
     if ($userfile['error'] || $userfile['size'] < 1) {
         throw new InstallHelperException('Upload error occured.');
     }
     // Temporary folder to extract the archive into
     $tmp_directory = $this->app->path->path('tmp:') . '/';
     $archivename = $tmp_directory . $userfile['name'];
     if (!JFile::upload($userfile['tmp_name'], $archivename)) {
         throw new InstallHelperException("Could not move uploaded file to ({$archivename})");
     }
     // Clean the paths to use for archive extraction
     $extractdir = $tmp_directory . uniqid('install_');
     jimport('joomla.filesystem.archive');
     // do the unpacking of the archive
     if (!JArchive::extract($archivename, $extractdir)) {
         throw new InstallHelperException("Could not extract zip file to ({$tmp_directory})");
     }
     return $this->installApplicationFromFolder($extractdir);
 }
 public function saveCategoryData($post)
 {
     //print_r($post);  die;
     $db = JFactory::getDbo();
     $creationDate = date('Y-m-d H:i:s');
     $query = $db->getQuery(true);
     $allawExtation = array('jpg', 'jpeg', 'png', 'gif');
     # These extantion allowed for upload logo file
     $file = JRequest::getVar('categoryLogo', null, 'files', 'array');
     $filename = JFile::makeSafe($file['name']);
     $filextantion = strtolower(JFile::getExt($filename));
     $fileScr = $file['tmp_name'];
     $error = $this->validate($post, $filename, $filextantion, $allawExtation, $fileScr);
     if (count($error) == 0) {
         // Logo update start there
         if ($filename != '') {
             $tempFname = time() . '.' . $filextantion;
             $logoName = str_replace(' ', '', $post['categoryName']) . '_' . $tempFname;
             # File name to store into database
             $src = $fileScr;
             $dest = JPATH_BASE . "/images/productLogo/" . $logoName;
             if (JFile::upload($src, $dest)) {
                 $conditional = $logoName;
             }
         }
         $columns = array('categoryName', 'categoryImage', 'creationDate');
         $values = array($db->quote($post['categoryName']), $db->quote($conditional), $db->quote($creationDate));
         $query->insert($db->quoteName('onm_product_category'))->columns($db->quoteName($columns))->values(implode(',', $values));
         $db->setQuery($query);
         $result = $db->execute();
         echo "<SCRIPT LANGUAGE='JavaScript'>\n    window.alert('Category Added')\n    window.location.href='index.php?option=com_membercheckin&view=addcategory';\n    </SCRIPT>";
     } else {
         return $error;
     }
 }
Example #11
0
 /**
  * Upload a file
  * @param	string	$source			File to upload
  * @param	string	$destination	Upload to here
  * @return True on success
  */
 public static function upload($source, $destination)
 {
     $err = null;
     $ret = false;
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Load configurations.
     $config = CFactory::getConfig();
     // Make the filename safe
     jimport('joomla.filesystem.file');
     if (!isset($source['name'])) {
         JError::raiseNotice(100, JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST'));
         return $ret;
     }
     $source['name'] = JFile::makeSafe($source['name']);
     if (is_dir($destination)) {
         jimport('joomla.filesystem.folder');
         JFolder::create($destination, (int) octdec($config->get('folderpermissionsvideo')));
         JFile::copy(JPATH_ROOT . '/components/com_community/index.html', $destination . '/index.html');
         $destination = JPath::clean($destination . '/' . strtolower($source['name']));
     }
     if (JFile::exists($destination)) {
         JError::raiseNotice(100, JText::_('COM_COMMUNITY_FILE_EXISTS'));
         return $ret;
     }
     if (!JFile::upload($source['tmp_name'], $destination)) {
         JError::raiseWarning(100, JText::_('COM_COMMUNITY_UNABLE_TO_UPLOAD_FILE'));
         return $ret;
     } else {
         $ret = true;
         return $ret;
     }
 }
Example #12
0
 /**
  * basic upload
  * @return bool
  */
 public function upload()
 {
     JRequest::checkToken() or die('Invalid Token');
     $appl = JFactory::getApplication();
     $file = JRequest::getVar('extension', '', 'files', 'array');
     if ($file['tmp_name']) {
         $path = $this->pathArchive;
         // if the archive folder doesn't exist - create it!
         if (!JFolder::exists($path)) {
             JFolder::create($path);
         } else {
             // let us remove all previous uploads
             $archiveFiles = JFolder::files($path);
             foreach ($archiveFiles as $archive) {
                 if (!JFile::delete($this->pathArchive . '/' . $archive)) {
                     echo 'could not delete' . $archive;
                 }
             }
         }
         $filepath = $path . '/' . strtolower($file['name']);
         $object_file = new JObject($file);
         $object_file->filepath = $filepath;
         $file = (array) $object_file;
         //          let us try to upload
         if (!JFile::upload($file['tmp_name'], $file['filepath'])) {
             // Error in upload
             JError::raiseWarning(100, JText::_('COM_JEDCHECKER_ERROR_UNABLE_TO_UPLOAD_FILE'));
             return false;
         }
         $appl->redirect('index.php?option=com_jedchecker&view=uploads', JText::_('COM_JEDCHECKER_UPLOAD_WAS_SUCCESSFUL'));
         return true;
     }
     return false;
 }
Example #13
0
 /**
  * Method to perform sanity checks on the JTable instance properties to ensure
  * they are safe to store in the database.  Child classes should override this
  * method to make sure the data they are storing in the database is safe and
  * as expected before storage.
  *
  * @return  boolean  True if the instance is sane and able to be stored in the database.
  *
  * @link    http://docs.joomla.org/JTable/check
  * @since   11.1
  */
 public function check()
 {
     $input = JFactory::getApplication()->input;
     $file = $input->files->get('jform', '', 'ARRAY');
     $post = $input->post->get('jform', '', 'ARRAY');
     $bookId = $post['book_id'];
     $file = $file['audio_upload'];
     if (empty($file['error'])) {
         // Make the filename safe
         $audioFile = JFile::makeSafe($file['name']);
         $fileExt = explode('.', $audioFile);
         if (isset($audioFile)) {
             $filepath = JPath::clean(JPATH_SITE . '/media/englishconcept/media/audio/' . strtolower(md5($bookId . $file['name'])) . '.' . $fileExt[1]);
             $objectFile = new JObject($file);
             $objectFile->filepath = $filepath;
             if (JFile::exists($objectFile->filepath)) {
                 JFile::delete($objectFile->filepath);
             }
             if (!JFile::upload($objectFile->tmp_name, $objectFile->filepath)) {
                 return false;
             }
         }
     }
     return true;
 }
 public function store($data)
 {
     $row =& $this->getTable('stockimage_detail');
     $file = JRequest::getVar('stock_amount_image', '', 'files', 'array');
     if ($_FILES['stock_amount_image']['name'] != "") {
         $ext = explode(".", $file['name']);
         $filetmpname = substr($file['name'], 0, strlen($file['name']) - strlen($ext[count($ext) - 1]));
         $filename = JPath::clean(time() . '_' . $filetmpname . "jpg");
         $row->stock_amount_image = $filename;
         $src = $file['tmp_name'];
         $dest = REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $filename;
         JFile::upload($src, $dest);
         if (isset($data['stock_image']) != "" && is_file(REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $data['stock_image'])) {
             unlink(REDSHOP_FRONT_IMAGES_RELPATH . 'stockroom/' . $data['stock_image']);
         }
     }
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     return $row;
 }
Example #15
0
 /**
  * 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;
 }
 /**
  * Upload Simple File Manager files in the right folder.
  *
  * @param string $tmp_name
  *            Temporary path of the uploaded file on the server
  * @param string $file_name
  *            Name of the uploaded file
  * @return uploaded file path (in case of success) or false (in case of error)
  */
 public static function uploadFile($tmp_name, $file_name)
 {
     jimport('joomla.filesystem.file');
     $src = $tmp_name;
     $dest = JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR . uniqid("", true) . DIRECTORY_SEPARATOR . JFile::makeSafe(JFile::getName($file_name));
     return JFile::upload($src, $dest) ? $dest : false;
 }
Example #17
0
 /**
  * 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;
 }
Example #18
0
 function getValue($field, $source_array)
 {
     jimport('joomla.filesystem.file');
     $upload_path = $field->getParam('upload_path', 'media' . DS . APP_EXTENSION . DS . 'files' . DS . $field->db_name);
     $allowed_extensions = explode(',', $field->getParam('file_extensions', 'jpg,gif,jpeg,png'));
     $delete_file = JArrayHelper::getValue($source_array, "{$field->db_name}_delete", 0, "INT");
     if ($delete_file) {
         return "";
     }
     $file = JRequest::getVar($field->db_name . '_replace', null, 'files');
     if (!$file['name']) {
         $file = JRequest::getVar($field->db_name, null, 'files');
     }
     $fname = $file['name'];
     if (!is_uploaded_file($file['tmp_name'])) {
         return null;
     }
     $ext = strtolower(JFile::getExt($fname));
     if (!in_array($ext, $allowed_extensions)) {
         return null;
     }
     $file_name = JFile::makesafe('custom-' . trim($field->db_name) . '-' . time() . ".{$ext}");
     JFile::upload($file['tmp_name'], $upload_path . DS . $file_name);
     return $file_name;
 }
Example #19
0
 /**
  * checks uploaded file, and uploads it
  * @return true csv file uploaded ok, false error (JErrir warning raised)
  */
 function checkUpload()
 {
     if (!(bool) ini_get('file_uploads')) {
         JError::raiseWarning(500, JText::_("The installer can't continue before file uploads are enabled. Please use the install from directory method."));
         return false;
     }
     $userfile = JRequest::getVar('userfile', null, 'files');
     if (!$userfile) {
         JError::raiseWarning(500, JText::_('No file selected'));
         return false;
     }
     jimport('joomla.filesystem.file');
     $allowed = array('txt', 'csv', 'tsv');
     if (!in_array(JFile::getExt($userfile['name']), $allowed)) {
         JError::raiseError(500, 'File must be a csv file');
         return false;
     }
     $config =& JFactory::getConfig();
     $tmp_dir = $config->getValue('config.tmp_path');
     if (empty($tmp_dir) || !JFolder::exists($tmp_dir)) {
         JError::raiseError(500, 'Joomla tmp_path not configured or does not exist');
         return false;
     }
     $tmp_name = 'fabrik_csv_' . md5(uniqid());
     $to = JPath::clean($tmp_dir . DS . $tmp_name);
     $resultdir = JFile::upload($userfile['tmp_name'], $to);
     if ($resultdir === false) {
         JError::raiseWarning(500, JText::_('Upload Error'));
         return false;
     }
     return $tmp_name;
 }
 function prepare($field_name)
 {
     $this->is_prepared = 0;
     $bbfile = mosGetParam($_FILES, $field_name, null);
     if (!extension_loaded('zlib')) {
         return "Error! zlib library unavailable";
     }
     if (!$bbfile) {
         return _JLMS_EM_SELECT_FILE;
     }
     $bbfile_name = $bbfile['name'];
     if (empty($bbfile_name)) {
         return _JLMS_EM_SELECT_FILE;
     }
     if (strcmp(substr($bbfile_name, -4, 1), ".")) {
         return _JLMS_EM_BAD_FILEEXT;
     }
     if (strcmp(substr($bbfile_name, -4), ".zip")) {
         return _JLMS_EM_BAD_FILEEXT;
     }
     $tmp_name = $bbfile['tmp_name'];
     if (!file_exists($tmp_name)) {
         return _JLMS_EM_UPLOAD_SIZE_ERROR;
     } else {
         #$this->$bb_filelocation = $tmp_name;
     }
     if (preg_match("/.zip\$/", strtolower($bbfile_name))) {
         $zipFile = new pclZip($tmp_name);
         $zipContentArray = $zipFile->listContent();
         $exp_xml_file = false;
         foreach ($zipContentArray as $thisContent) {
             if (preg_match('~.(php.*|phtml)$~i', $thisContent['filename'])) {
                 return _JLMS_EM_READ_PACKAGE_ERROR;
             }
             if ($thisContent['filename'] == 'imsmanifest.xml') {
                 $exp_xml_file = true;
             }
         }
         if ($exp_xml_file == false) {
             return "Could not find a Course XML setup file in the package.";
         }
     } else {
         return _JLMS_EM_BAD_FILEEXT;
     }
     $config =& JFactory::getConfig();
     $tmp_dest = $config->getValue('config.tmp_path') . DS . $bbfile['name'];
     $tmp_src = $bbfile['tmp_name'];
     // Move uploaded file
     jimport('joomla.filesystem.file');
     $uploaded = JFile::upload($tmp_src, $tmp_dest);
     if ($uploaded) {
         $this->bb_file_media_name = '';
         $this->bb_file_tmp_name = $tmp_dest;
         $this->is_prepared = 1;
         return '';
     } else {
         return 'File not found';
     }
 }
Example #21
0
 function install()
 {
     $tmp = JPATH_ROOT . '/tmp/kinstall/';
     $dest = KPATH_SITE . '/template/';
     $file = JRequest::getVar('install_package', null, 'files', 'array');
     // File upload
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->app->redirect(KunenaRoute::_($this->baseurl, false));
     }
     if (empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name']) || !empty($file['error'])) {
         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_MISSING', $this->escape($file['name'])), 'notice');
     } else {
         $success = JFile::upload($file['tmp_name'], $tmp . $file['name']);
         if ($success) {
             $success = JArchive::extract($tmp . $file['name'], $tmp);
         }
         if (!$success) {
             $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_FAILED', $this->escape($file['name'])), 'notice');
         }
         // Delete the tmp install directory
         if (JFolder::exists($tmp)) {
             $templates = KunenaTemplateHelper::parseXmlFiles($tmp);
             if (!empty($templates)) {
                 foreach ($templates as $template) {
                     // Never overwrite locked templates
                     if (in_array($template->directory, $this->locked)) {
                         continue;
                     }
                     if (is_dir($dest . $template->directory)) {
                         if (is_file($dest . $template->directory . '/params.ini')) {
                             if (is_file($tmp . $template->sourcedir . '/params.ini')) {
                                 JFile::delete($tmp . $template->sourcedir . '/params.ini');
                             }
                             JFile::move($dest . $template->directory . '/params.ini', $tmp . $template->sourcedir . '/params.ini');
                         }
                         JFolder::delete($dest . $template->directory);
                     }
                     $success = JFolder::move($tmp . $template->sourcedir, $dest . $template->directory);
                     if ($success !== true) {
                         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_FAILED', $template->directory), 'notice');
                     } else {
                         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_SUCCESS', $template->directory));
                     }
                 }
                 if (file_exists($tmp)) {
                     JFolder::delete($tmp);
                 }
                 // Clear all cache, just in case.
                 KunenaCacheHelper::clearAll();
             } else {
                 JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_MISSING_FILE'));
             }
         } else {
             JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ' ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_DIR_NOT_EXIST'));
         }
     }
     $this->app->redirect(KunenaRoute::_($this->baseurl, false));
 }
Example #22
0
 public function upload($file)
 {
     jimport('joomla.filesystem.file');
     // Upload it to the temp location.
     if (!JFile::upload($file['tmp_name'], $this->getPath())) {
         throw new Exception(sprintf('Could not copy "%s" to "%s"!', $file['name'], $this->path));
     }
 }
 /**
  * upload
  *
  * @param \JInput    $input
  */
 public static function upload(\JInput $input)
 {
     try {
         $editorPlugin = \JPluginHelper::getPlugin('editors', 'akmarkdown');
         if (!$editorPlugin) {
             throw new \Exception('Editor Akmarkdown not exists');
         }
         $params = new Registry($editorPlugin->params);
         $files = $input->files;
         $field = $input->get('field', 'file');
         $type = $input->get('type', 'post');
         $allows = $params->get('Upload_AllowExtension', '');
         $allows = array_map('strtolower', array_map('trim', explode(',', $allows)));
         $file = $files->getVar($field);
         $src = $file['tmp_name'];
         $name = $file['name'];
         $tmp = new \SplFileInfo(JPATH_ROOT . '/tmp/ak-upload/' . $name);
         if (empty($file['tmp_name'])) {
             throw new \Exception('File not upload');
         }
         $ext = pathinfo($name, PATHINFO_EXTENSION);
         if (!in_array($ext, $allows)) {
             throw new \Exception('File extension now allowed.');
         }
         // Move file to tmp
         if (!is_dir($tmp->getPath())) {
             \JFolder::create($tmp->getPath());
         }
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         \JFile::upload($src, $tmp->getPathname());
         $src = $tmp;
         $dest = static::getDest($name, $params->get('Upload_S3_Subfolder', 'ak-upload'));
         $s3 = new \S3($params->get('Upload_S3_Key'), $params->get('Upload_S3_SecretKey'));
         $bucket = $params->get('Upload_S3_Bucket');
         $result = $s3::putObject(\S3::inputFile($src->getPathname(), false), $bucket, $dest, \S3::ACL_PUBLIC_READ);
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         if (!$result) {
             throw new \Exception('Upload fail.');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new \JRegistry();
     $return['filename'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $return['file'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
 }
 public function upload()
 {
     $app = JFactory::getApplication();
     $this->getInputData();
     try {
         jimport('joomla.user.authentication');
         $auth =& JAuthentication::getInstance();
         $credentials = array('username' => $this->username, 'password' => $this->password);
         $response = $auth->authenticate($credentials, array());
         if ($response->status !== JAUTHENTICATE_STATUS_SUCCESS) {
             throw new Exception("Authentification error: {$response->status}");
         }
         $tmpdir = JPath::clean($app->getCfg("tmp_path"));
         if (!JFolder::exists($tmpdir)) {
             throw new Exception("Could not open temporary directory");
         }
         if (!is_array($this->xmlfile)) {
             throw new Exception("No xml file found");
         }
         $xmlpath = $tmpdir . "/" . $this->xmlfile["name"];
         if (!JFile::upload($this->xmlfile["tmp_name"], $xmlpath)) {
             throw new Exception("Error uploading xml file");
         }
         $xml = new SimpleXMLElement($xmlpath, 0, true);
         $data = array();
         $mode = (string) $xml->getName();
         foreach ($xml->THE_FIRM as $firm) {
             $item = array();
             $item["inn"] = (string) $firm["inn"];
             $itemDT = DateTime::createFromFormat("d.m.Y H:i:s", (string) $firm->DateTime);
             $item["adding_date"] = $itemDT->format("Y-m-d H:i:s");
             if ($mode == "AddChange") {
                 $item["name"] = (string) $firm->Name;
                 $item["address"] = (string) $firm->Address;
                 $item["certificate1"] = (string) $firm->Number;
             }
             $data[$item["inn"]] = $item;
         }
         $model = $this->getModel("Items", "SroModel");
         if (!$model->update($data, $mode)) {
             throw new Exception($model->getError());
         }
         if (is_array($this->docfile)) {
             $config = SroHelper::getConfig();
             $docpath = $config->get("rootfolder");
             $docpath = JPATH_SITE . "/" . JPath::clean($docpath) . "/" . $this->docfile["name"];
             if (!JFile::upload($this->docfile["tmp_name"], $docpath)) {
                 throw new Exception("Error uploading data file");
             }
         }
     } catch (Exception $e) {
         if ($this->talk) {
             echo $e->getMessage();
         }
     }
     $app->close();
 }
Example #25
0
 function install()
 {
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.archive');
     $tmp = JPATH_ROOT . '/tmp/kinstall/';
     $dest = KPATH_SITE . '/template/';
     $file = JRequest::getVar('install_package', NULL, 'FILES', 'array');
     if (!JRequest::checkToken()) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->app->redirect(KunenaRoute::_($this->baseurl, false));
     }
     if (!$file || !is_uploaded_file($file['tmp_name'])) {
         $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_MISSING', $file['name']), 'notice');
     } else {
         $success = JFile::upload($file['tmp_name'], $tmp . $file['name']);
         $success = JArchive::extract($tmp . $file['name'], $tmp);
         if (!$success) {
             $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_FAILED', $file['name']), 'notice');
         }
         // Delete the tmp install directory
         if (JFolder::exists($tmp)) {
             $templates = KunenaTemplateHelper::parseXmlFiles($tmp);
             if (!empty($templates)) {
                 foreach ($templates as $template) {
                     // Never overwrite default template
                     if ($template->directory == 'default') {
                         continue;
                     }
                     if (is_dir($dest . $template->directory)) {
                         if (is_file($dest . $template->directory . '/params.ini')) {
                             if (is_file($tmp . $template->directory . '/params.ini')) {
                                 JFile::delete($tmp . $template->directory . '/params.ini');
                             }
                             JFile::move($dest . $template->directory . '/params.ini', $tmp . $template->directory . '/params.ini');
                         }
                         JFolder::delete($dest . $template->directory);
                     }
                     $error = JFolder::move($tmp . $template->directory, $dest . $template->directory);
                     if ($error !== true) {
                         $this->app->enqueueMessage(JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ': ' . $error, 'notice');
                     }
                 }
                 $retval = JFolder::delete($tmp);
                 $this->app->enqueueMessage(JText::sprintf('COM_KUNENA_A_TEMPLATE_MANAGER_INSTALL_EXTRACT_SUCCESS', $file['name']));
             } else {
                 JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE_MISSING_FILE'));
                 $retval = false;
             }
         } else {
             JError::raiseWarning(100, JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_TEMPLATE') . ' ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_UNINSTALL') . ': ' . JText::_('COM_KUNENA_A_TEMPLATE_MANAGER_DIR_NOT_EXIST'));
             $retval = false;
         }
     }
     $this->app->redirect(KunenaRoute::_($this->baseurl, false));
 }
Example #26
0
 public function upload()
 {
     $files = JRequest::get('files');
     $upload = $files['upload'];
     if (!$files['error']) {
         return JFile::upload($upload['tmp_name'], $this->getCurrent() . '/' . JFile::getName($upload['name']));
     } else {
         return false;
     }
 }
Example #27
0
 public function savePropertyData($post)
 {
     //print_r($post);
     $db = JFactory::getDbo();
     $allawExtation = array('jpg', 'jpeg', 'png', 'gif');
     #These extantion allowed for upload logo file
     $file = JRequest::getVar('propertyLogo', null, 'files', 'array');
     $filename = JFile::makeSafe($file['name']);
     $filextantion = strtolower(JFile::getExt($filename));
     $fileScr = $file['tmp_name'];
     $error = $this->validate($post, $filename, $filextantion, $allawExtation, $fileScr);
     if (count($error) == 0) {
         // Logo update start there
         if ($filename != '') {
             $tempFname = time() . '.' . $filextantion;
             $logoName = str_replace(' ', '', $post['propertyName']) . '_' . $tempFname;
             # File name to store into database
             $src = $fileScr;
             $dest = JPATH_BASE . "/images/productLogo/" . $logoName;
             if (JFile::upload($src, $dest)) {
                 $conditional = $logoName;
             }
         }
         // Logo update end there
         ##############################################
         $file1 = JRequest::getVar('googlemapLogo', null, 'files', 'array');
         $filename1 = JFile::makeSafe($file1['name']);
         $filextantion1 = strtolower(JFile::getExt($filename1));
         $fileScr1 = $file1['tmp_name'];
         if ($filename1 != '') {
             $tempFname1 = uniqid() . time() . '.' . $filextantion1;
             $logoName1 = str_replace(' ', '', $post['propertyName']) . '_' . $tempFname1;
             # File name to store into database
             $src1 = $fileScr1;
             $dest1 = JPATH_BASE . "/images/productLogo/" . $logoName1;
             if (JFile::upload($src1, $dest1)) {
                 $conditional1 = $logoName1;
             }
         }
         // Logo update end there
         #############################################
         $query = $db->getQuery(true);
         $fields = array($db->quoteName('propertyName') . ' = ' . $db->quote($post['propertyName']), $db->quoteName('propertyAddress') . ' = ' . $db->quote($post['propertyAddress']), $db->quoteName('productLogo') . ' = ' . $db->quote($conditional), $db->quoteName('offerLogoThumb') . ' = ' . $db->quote($conditional1), $db->quoteName('propertyDesc') . ' = ' . $db->quote($post['propertyDesc']), $db->quoteName('propertyPrice') . ' = ' . $db->quote($post['propertyPrice']), $db->quoteName('termscondition') . ' = ' . $db->quote($post['termscondition']));
         $conditions = array($db->quoteName('propertyID') . ' = ' . $db->quote($_GET['productID']));
         $query->update($db->quoteName('#__property'))->set($fields)->where($conditions);
         $db->setQuery($query);
         $result = $db->execute();
         $db->query();
         $app = JFactory::getApplication();
         $urlRed = "index.php?option=com_membercheckin&view=propertylist";
         $app->redirect($urlRed);
     } else {
         return $error;
     }
 }
Example #28
0
 function _install($file)
 {
     $AG_resourceType = JRequest::getVar('AG_resourceType');
     // Current resource type
     $config = JFactory::getConfig();
     $tmp_dest = $config->get('tmp_path');
     $resourceType = substr($AG_resourceType, 0, strlen($AG_resourceType) - 1);
     $file_type = "zip";
     if (isset($file) && !empty($file['name'])) {
         //Clean up filename to get rid of strange characters like spaces etc
         $filename = JFile::makeSafe($file['name']);
         $ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
         $src = $file['tmp_name'];
         $dest = $tmp_dest . DIRECTORY_SEPARATOR . $filename;
         //First check if the file has the right extension
         if ($ext == $file_type) {
             if (JFile::upload($src, $dest)) {
                 if (JArchive::extract($tmp_dest . DIRECTORY_SEPARATOR . $filename, $tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType)) {
                     JFile::delete($tmp_dest . DIRECTORY_SEPARATOR . $filename);
                 }
                 // TEMPLATE DETAILS PARSING
                 if (JFIle::exists($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType . DIRECTORY_SEPARATOR . JFile::stripExt($filename) . DIRECTORY_SEPARATOR . 'details.xml')) {
                     $ag_resourceManager_xml =& JFactory::getXML($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType . DIRECTORY_SEPARATOR . JFile::stripExt($filename) . DIRECTORY_SEPARATOR . 'details.xml');
                     if (isset($ag_resourceManager_xml->type)) {
                         $ag_resourceManager_type = $ag_resourceManager_xml->type;
                     } else {
                         JFolder::delete($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType);
                         JFactory::getApplication()->enqueueMessage(JText::_('AG_ZIP_PACKAGE_IS_NOT_VALID_RESOURCE_TYPE') . "&nbsp;" . $filename, 'error');
                         return;
                     }
                 } else {
                     JFolder::delete($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType);
                     JFactory::getApplication()->enqueueMessage(JText::_('AG_ZIP_PACKAGE_IS_NOT_VALID_RESOURCE_TYPE') . "&nbsp;" . $filename, 'error');
                     return;
                 }
                 if ($ag_resourceManager_type && $ag_resourceManager_type == $resourceType) {
                     $result = JFolder::move($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType . DIRECTORY_SEPARATOR . JFile::stripExt($filename), JPATH_SITE . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'admirorgallery' . DIRECTORY_SEPARATOR . 'admirorgallery' . DIRECTORY_SEPARATOR . $AG_resourceType . DIRECTORY_SEPARATOR . JFile::stripExt($filename));
                     if ($result) {
                         JFactory::getApplication()->enqueueMessage(JText::_('AG_ZIP_PACKAGE_IS_INSTALLED') . "&nbsp;" . $filename, 'message');
                     } else {
                         JFactory::getApplication()->enqueueMessage(JText::_('AG_CANNOT_MOVED_ITEM') . "&nbsp;" . $result, 'message');
                     }
                 } else {
                     JFolder::delete($tmp_dest . DIRECTORY_SEPARATOR . $AG_resourceType);
                     JFactory::getApplication()->enqueueMessage(JText::_('AG_ZIP_PACKAGE_IS_NOT_VALID_RESOURCE_TYPE') . "&nbsp;" . $filename, 'error');
                 }
             } else {
                 JFactory::getApplication()->enqueueMessage(JText::_('AG_CANNOT_UPLOAD_FILE_TO_TEMP_FOLDER_PLEASE_CHECK_PERMISSIONS'), 'error');
             }
         } else {
             JFactory::getApplication()->enqueueMessage(JText::_('AG_ONLY_ZIP_ARCHIVES_CAN_BE_INSTALLED'), 'error');
         }
     }
 }
Example #29
0
 /**
  * Upload package from local
  */
 function getPackageFromUpload()
 {
     $this->checkFileUpload();
     $user_file = JRequest::getVar('install_package', null, 'files', 'array');
     $tmp_dest = JPath::clean(JPATH_ROOT . DS . 'tmp' . DS . $user_file['name']);
     $tmp_src = $user_file['tmp_name'];
     if (!JFile::upload($tmp_src, $tmp_dest)) {
         $error = JText::_('FOLDER TMP IS UNWRITE');
         $this->returnError('false', $error);
     }
     return $user_file['name'];
 }
Example #30
-1
 function import_rules()
 {
     $app = JFactory::getApplication();
     $file = $app->input->files->get('rule-file', array(), 'array');
     if ($file['error'] > 0) {
         $this->setError('File/File Size Error. File Error=' . $file['error'] . '| File Size=' . $file['size']);
         return false;
     }
     //check the file extension is ok
     if (JFile::getExt($file['name']) != 'xml') {
         $this->setError('Invalid file extension.');
         return false;
     }
     $plugin = simplexml_load_file($file['tmp_name']);
     if (empty($plugin) || empty($plugin['name']) || $plugin['type'] != 'cjblog_badges') {
         return false;
     }
     $filename = $plugin['name'] . '.xml';
     if (file_exists($filename)) {
         return false;
     }
     if (JFile::upload($file['tmp_name'], CJBLOG_PLUGINS_BASE_DIR . 'badges/' . $filename)) {
         return true;
     }
     return false;
 }