Example #1
0
function uploadImage($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
    $filenameTmp = JFile::makeSafe($file['name']);
    $ext = strtolower(JFile::getExt($filenameTmp));
    $filename = str_replace(' ', '-', JFile::stripExt($filenameTmp)) . '.' . $ext;
    $src = $file['tmp_name'];
    $dest = $path . $filename;
    //First check if the file has the right extension, we need jpg only
    if ($ext == 'jpg' or $ext == 'gif' or $ext == 'png' or $ext == 'jpeg' or $ext == 'zip' or $ext = 'rar' or $ext = 'pdf') {
        //check exits
        if (!$override) {
            if (JFile::exists($dest)) {
                $dest = checkExists($filenameTmp, $ext);
            }
        }
        if (JFile::upload($src, $dest)) {
            return $filename;
        } else {
            echo "Error upload image";
            exit;
        }
    } else {
        echo "Chi cho phep cac loai anh: jpg, gif, png";
        exit;
    }
    return false;
}
Example #2
0
 /**
  * Method to delete record(s)
  *
  * @access    public
  * @param array $pks
  * @return    boolean    True on success
  */
 function delete(&$pks)
 {
     $row = $this->getTable();
     if (count($pks)) {
         foreach ($pks as $cid) {
             $query = $this->_db->getQuery(true)->select('*')->from($this->_db->quoteName('#__eventgallery_file'))->where('id=' . $this->_db->quote($cid));
             $this->_db->setQuery($query);
             $data = $this->_db->loadObject();
             $path = JPATH_SITE . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'eventgallery' . DIRECTORY_SEPARATOR . JFile::makeSafe($data->folder) . DIRECTORY_SEPARATOR;
             $filename = JFile::makeSafe($data->file);
             $file = $path . $filename;
             if (file_exists($file) && !is_dir($file)) {
                 if (!unlink($file)) {
                     echo $file;
                     return false;
                 }
             }
             if (!$row->delete($cid)) {
                 $this->setError($row->getErrorMsg());
                 return false;
             }
         }
     }
     return true;
 }
Example #3
0
 function loadJSfile($file)
 {
     jimport('joomla.filesystem.file');
     $file = JFile::makeSafe($file);
     $pa = pathinfo($file);
     $fullpath = JPATH_SITE . DS . 'components' . DS . 'com_onepage' . DS . 'assets' . DS . 'js' . DS . $file;
     if (!empty($pa['extension'])) {
         if ($pa['extension'] == 'js') {
             //http://php.net/manual/en/function.header.php
             if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == false) {
                 @header("Content-type: text/javascript");
                 @header("Content-Disposition: inline; filename=\"" . $file . "\"");
                 //@header("Content-Length: ".filesize($fullpath));
             } else {
                 @header("Content-type: application/force-download");
                 @header("Content-Disposition: attachment; filename=\"" . $file . "\"");
                 //@header("Content-Length: ".filesize($fullpath));
             }
             @header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
             if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == false) {
                 @header("Cache-Control: no-cache");
                 @header("Pragma: no-cache");
             }
             //include(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'assets'.DS.'js'.DS.$file);
             echo file_get_contents($fullpath);
             $doc = JFactory::getApplication();
             $doc->close();
             die;
         }
     }
 }
Example #4
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']);
         }
     }
 }
Example #5
0
 public function uploadFiles($files, $options)
 {
     $result = array();
     $destination = JArrayHelper::getValue($options, "destination");
     $maxSize = JArrayHelper::getValue($options, "max_size");
     $legalExtensions = JArrayHelper::getValue($options, "legal_extensions");
     $legalFileTypes = JArrayHelper::getValue($options, "legal_types");
     // check for error
     foreach ($files as $fileData) {
         // Upload image
         if (!empty($fileData['name'])) {
             $uploadedFile = JArrayHelper::getValue($fileData, 'tmp_name');
             $uploadedName = JArrayHelper::getValue($fileData, 'name');
             $errorCode = JArrayHelper::getValue($fileData, 'error');
             $file = new Prism\File\File();
             // Prepare size validator.
             $KB = 1024 * 1024;
             $fileSize = JArrayHelper::getValue($fileData, "size");
             $uploadMaxSize = $maxSize * $KB;
             // Prepare file size validator
             $sizeValidator = new Prism\File\Validator\Size($fileSize, $uploadMaxSize);
             // Prepare server validator.
             $serverValidator = new Prism\File\Validator\Server($errorCode, array(UPLOAD_ERR_NO_FILE));
             // Prepare image validator.
             $typeValidator = new Prism\File\Validator\Type($uploadedFile, $uploadedName);
             // Get allowed MIME types.
             $mimeTypes = explode(",", $legalFileTypes);
             $mimeTypes = array_map('trim', $mimeTypes);
             $typeValidator->setMimeTypes($mimeTypes);
             // Get allowed file extensions.
             $fileExtensions = explode(",", $legalExtensions);
             $fileExtensions = array_map('trim', $fileExtensions);
             $typeValidator->setLegalExtensions($fileExtensions);
             $file->addValidator($sizeValidator)->addValidator($typeValidator)->addValidator($serverValidator);
             // Validate the file
             if (!$file->isValid()) {
                 throw new RuntimeException($file->getError());
             }
             // Generate file name
             $baseName = JString::strtolower(JFile::makeSafe(basename($fileData['name'])));
             $ext = JFile::getExt($baseName);
             $generatedName = new Prism\String();
             $generatedName->generateRandomString(6);
             $destinationFile = $destination . DIRECTORY_SEPARATOR . $generatedName . "." . $ext;
             // Prepare uploader object.
             $uploader = new Prism\File\Uploader\Local($uploadedFile);
             $uploader->setDestination($destinationFile);
             // Upload temporary file
             $file->setUploader($uploader);
             $file->upload();
             // Get file
             $fileSource = $file->getFile();
             if (!JFile::exists($fileSource)) {
                 throw new RuntimeException(JText::_("COM_CROWDFUNDING_ERROR_FILE_CANT_BE_UPLOADED"));
             }
             $result[] = array("title" => $baseName, "filename" => basename($fileSource));
         }
     }
     return $result;
 }
 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;
     }
 }
 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;
 }
 /**
  * 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 #9
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 #10
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;
 }
Example #11
0
 public static function createThumb($path, $width = 100, $height = 100, $crop = 2)
 {
     $myImage = new JImage();
     $myImage->loadFile(JPATH_SITE . DS . $path);
     if ($myImage->isLoaded()) {
         // $filename = end(explode('/', $path));
         $filename = JFile::getName($path);
         $filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
         $newfilename = $width . 'x' . $height . '_' . $filefolder . '_' . JFile::makeSafe($filename);
         $fileExists = JFile::exists(JPATH_CACHE . '/' . $newfilename);
         if (!$fileExists) {
             $resizedImage = $myImage->resize($width, $height, true, $crop);
             $properties = $myImage->getImageFileProperties($path);
             $mime = $properties->mime;
             if ($mime == 'image/jpeg') {
                 $type = IMAGETYPE_JPEG;
             } elseif ($mime = 'image/png') {
                 $type = IMAGETYPE_PNG;
             } elseif ($mime = 'image/gif') {
                 $type = IMAGETYPE_GIF;
             }
             $resizedImage->toFile(JPATH_CACHE . '/' . $newfilename, $type);
         }
         return $newfilename;
     } else {
         return "My file is not loaded";
     }
 }
Example #12
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;
 }
Example #13
0
 /**
  * Create a thumbnail from an image file.
  *
  * <code>
  * $myFile   = "/tmp/myfile.jpg";
  *
  * $options = array(
  *     "destination" => "image/mypic.jpg",
  *     "width" => 200,
  *     "height" => 200,
  *     "scale" => JImage::SCALE_INSIDE
  * );
  *
  * $file = new PrismFileImage($myFile);
  * $file->createThumbnail($options);
  *
  * </code>
  *
  * @param  array $options Some options used in the process of generating thumbnail.
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  *
  * @return string A location to the new file.
  */
 public function createThumbnail($options)
 {
     $width = ArrayHelper::getValue($options, "width", 100);
     $height = ArrayHelper::getValue($options, "height", 100);
     $scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
     $destination = ArrayHelper::getValue($options, "destination");
     if (!$destination) {
         throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
     }
     // Generate thumbnail.
     $image = new \JImage();
     $image->loadFile($this->file);
     if (!$image->isLoaded()) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
     }
     // Resize the file as a new object
     $thumb = $image->resize($width, $height, true, $scale);
     $fileName = basename($this->file);
     $ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
     switch ($ext) {
         case "gif":
             $type = IMAGETYPE_GIF;
             break;
         case "png":
             $type = IMAGETYPE_PNG;
             break;
         case IMAGETYPE_JPEG:
         default:
             $type = IMAGETYPE_JPEG;
     }
     $thumb->toFile($destination, $type);
     return $destination;
 }
Example #14
0
 /**
  * K2importViewSelectcategory view display method
  * The view for selecting the Main Category for the import and to configure the import
  * @return void
  **/
 function display($tpl = null)
 {
     JToolBarHelper::title(JText::_('K2 Import Tool') . ' - ' . JText::_('configure the import'), 'generic.png');
     // $data =& $this->get( 'Data');
     $model =& $this->getModel();
     $modus = JRequest::getVar('modus', '', 'get', 'string');
     if ($modus == 'archive') {
         $mainframe = JFactory::getApplication();
         $file = JFolder::files($mainframe->getCfg('tmp_path') . DS . 'k2_import', '.csv');
         $this->assignRef('file', $file);
         $this->assignRef('modus', $modus);
     } else {
         $file = JRequest::getVar('file', '', 'get', 'string');
         $file = JFile::makeSafe($file);
         $this->assignRef('file', $file);
     }
     $k2categories = $model->getK2categories();
     $k2extrafieldgroups = $model->getK2extrafieldgroups();
     $this->assignRef('k2extrafieldgroups', $k2extrafieldgroups);
     $this->assignRef('k2categories', $k2categories);
     $document =& JFactory::getDocument();
     $document->addStyleSheet('components/com_k2import/css/k2import.css');
     if (version_compare(JVERSION, '1.6.0', 'ge')) {
         $document->addScript('components/com_k2import/js/k2import_1_6.js');
     } else {
         $document->addScript('components/com_k2import/js/k2import_1_5.js');
     }
     parent::display($tpl);
 }
Example #15
0
 /**
  * Makes file name safe to use
  * @param string The name of the file (not full path)
  * @return string The sanitised string
  */
 function makeSafe($file)
 {
     jimport('joomla.filesystem.file');
     $file = trim($file);
     $file = JFile::makeSafe($file);
     $file = preg_replace('#\\s#', '', $file);
     return $file;
 }
Example #16
0
 /**
  * Deletes paths from the current path
  *
  * @param string $listFolder The image directory to delete a file from
  * @since 1.5
  */
 function delete()
 {
     global $mainframe;
     JRequest::checkToken('request') or jexit('Invalid Token');
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Get some data from the request
     $tmpl = JRequest::getCmd('tmpl');
     $paths = JRequest::getVar('rm', array(), '', 'array');
     $folder = JRequest::getVar('folder', '', '', 'path');
     // Initialize variables
     $msg = array();
     $ret = true;
     if (count($paths)) {
         foreach ($paths as $path) {
             if ($path !== JFile::makeSafe($path)) {
                 JError::raiseWarning(100, JText::_('Unable to delete:') . htmlspecialchars($path, ENT_COMPAT, 'UTF-8') . ' ' . JText::_('WARNDIRNAME'));
                 continue;
             }
             $fullPath = JPath::clean(JA_WORKING_DATA_FOLDER . DS . $folder . DS . $path);
             if (is_file($fullPath)) {
                 $ret |= !JFile::delete($fullPath);
             } else {
                 if (is_dir($fullPath)) {
                     $files = JFolder::files($fullPath, '.', true);
                     $canDelete = true;
                     foreach ($files as $file) {
                         if ($file != 'index.html') {
                             $canDelete = false;
                         }
                     }
                     if ($canDelete) {
                         $ret |= !JFolder::delete($fullPath);
                     } else {
                         //allow remove folder not empty on local repository
                         $ret2 = JFolder::delete($fullPath);
                         $ret |= !$ret2;
                         if ($ret2 == false) {
                             JError::raiseWarning(100, JText::_('Unable to delete:') . $fullPath);
                         }
                     }
                 }
             }
         }
     }
     if ($ret) {
         JError::raiseNotice(200, JText::_('Successfully delete a seleted item(s).'));
     }
     if ($tmpl == 'component') {
         // We are inside the iframe
         $mainframe->redirect('index.php?option=' . JACOMPONENT . '&view=repolist&folder=' . $folder . '&tmpl=component');
     } else {
         $mainframe->redirect('index.php?option=' . JACOMPONENT . '&view=repolist&folder=' . $folder);
     }
 }
Example #17
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 #18
0
 private function loadSafeRequestVars()
 {
     if (JRequest::getVar('controller') == 'file') {
         $pathObject = GalleryHelper::splitPath(JRequest::getString('path', ''), false);
         $this->currentRequestPath = JFolder::makeSafe($pathObject->folderPath);
         $this->currentRequestFilename = JFile::makeSafe($pathObject->filename);
     } else {
         $this->currentRequestPath = JFolder::makeSafe(JRequest::getString('path', ''));
         $this->currentRequestFilename = '';
     }
 }
Example #19
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 #20
0
 function makeSafe($file = '')
 {
     $lang = JFactory::getLanguage();
     $file = $lang->transliterate($file);
     if (function_exists('mb_ereg_replace')) {
         $regex = array('#(\\.){2,}#', '#[^\\w\\.\\- ]#', '#^\\.#');
         return mb_ereg_replace($regex, '', $file);
     } else {
         jimport('joomla.filesystem.file');
         return JFile::makeSafe($file);
     }
 }
Example #21
0
 public static function splitPath($path, $makeRelative = true)
 {
     if ($makeRelative) {
         $path = GalleryHelper::makeRelative($path);
     }
     $parts = explode('/', $path);
     $object = new ArrayObject();
     $object->filename = JFile::makeSafe(array_pop($parts));
     // last element is filename
     $object->folderPath = JFolder::makeSafe(implode(DS, $parts));
     // use rest as path
     return $object;
 }
Example #22
0
 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;
 }
Example #23
0
 public function save()
 {
     JRequest::checkToken('request') or jexit(JText::_('JINVALID_TOKEN'));
     JTable::addIncludePath(JPATH_COMPONENT . '/tables');
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     $row = JTable::getInstance('Document', 'OsdownloadsTable');
     $post = JRequest::get('post');
     $row->bind($post['jform']);
     $text = $post['jform']['description_1'];
     $text = str_replace('<br>', '<br />', $text);
     $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i';
     $tagPos = preg_match($pattern, $text);
     if ($tagPos == 0) {
         $row->brief = $text;
         $row->description_1 = "";
     } else {
         list($row->brief, $row->description_1) = preg_split($pattern, $text, 2);
     }
     $row->require_email = (int) $row->require_email;
     $row->require_agree = (int) $row->require_agree;
     if (version_compare(JVERSION, '3.0', 'lt') && !empty($post['id'])) {
         $row->id = $post['id'];
     }
     $files = JRequest::get('files');
     $file = $files['jform'];
     if (!empty($file['name'])) {
         $file["name"]['file'] = JFile::makeSafe($file["name"]['file']);
         if (isset($file["name"]['file']) && $file["name"]['file']) {
             $uploadDir = JPATH_SITE . "/media/com_osdownloads/files/";
             if (isset($post["old_file"]) && JFile::exists(JPath::clean($uploadDir . $post["old_file"]))) {
                 unlink(JPath::clean($uploadDir . $post["old_file"]));
             }
             if (!JFolder::exists(JPath::clean($uploadDir))) {
                 JFolder::create(JPath::clean($uploadDir));
             }
             $timestamp = md5(microtime());
             $filepath = JPath::clean($uploadDir . $timestamp . "_" . $file["name"]['file']);
             $row->file_path = $timestamp . "_" . $file["name"]['file'];
             JFile::upload($file["tmp_name"]['file'], $filepath);
         }
     }
     $row->store();
     switch ($this->getTask()) {
         case "apply":
             $this->setRedirect("index.php?option=com_osdownloads&view=file&cid=" . $row->id, JText::_("COM_OSDOWNLOADS_DOCUMENT_IS_SAVED"));
             break;
         default:
             $this->setRedirect("index.php?option=com_osdownloads&view=files", JText::_("COM_OSDOWNLOADS_DOCUMENT_IS_SAVED"));
     }
 }
Example #24
0
 protected function DoUpload()
 {
     $file = JRequest::getVar('b2jstdupload', NULL, 'files', 'array');
     if (!$this->Submitted || !$file || $file['error'] == UPLOAD_ERR_NO_FILE) {
         return true;
     }
     $upload_directory = JPATH_SITE . "/components/" . $GLOBALS["com_name"] . "/uploads/";
     if (!is_writable($upload_directory)) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_DIR_NOT_WRITABLE'), B2JMessageBoard::error);
         return false;
     }
     if ($file['error']) {
         $this->MessageBoard->Add(JText::sprintf($GLOBALS["COM_NAME"] . '_ERR_UPLOAD', $file['error']), B2JMessageBoard::error);
         return false;
     }
     $size = $file['size'];
     if ($size == 0) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_EMPTY'), B2JMessageBoard::error);
         return false;
     }
     $max_filesize = intval($this->Params->get("uploadmax_file_size", "0")) * KB;
     if ($size > $max_filesize) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_FILE_TOO_LARGE'), B2JMessageBoard::error);
         return false;
     }
     $mimetype = new B2JMimeType();
     if (!$mimetype->Check($file['tmp_name'], $this->Params)) {
         $this->MessageBoard->Add(JText::_($GLOBALS["COM_NAME"] . '_ERR_MIME') . " [" . $mimetype->Mimetype . "]", B2JMessageBoard::error);
         return false;
     }
     jimport('joomla.filesystem.file');
     $filename = JFile::makeSafe($file['name']);
     $filename = uniqid() . "-" . $filename;
     $dest = $upload_directory . $filename;
     if (!JFile::upload($file['tmp_name'], $dest)) {
         return false;
     }
     $jsession =& JFactory::getSession();
     $b2jsession = new B2JSession($jsession->getId(), $this->Application->b2jcomid, $this->Application->b2jmoduleid, $this->Application->bid);
     // session_id, cid, mid
     $data = $b2jsession->Load('filelist');
     if ($data) {
         $filelist = explode("|", $data);
     } else {
         $filelist = array();
     }
     $filelist[] = $filename;
     $data = implode("|", $filelist);
     $b2jsession->Save($data, "filelist");
     return true;
 }
Example #25
0
 public function uploadFile($fileData, $type)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationAdministrator */
     jimport('joomla.filesystem.archive');
     jimport('itprism.file');
     jimport('itprism.file.uploader.local');
     jimport('itprism.file.validator.size');
     jimport('itprism.file.validator.server');
     $uploadedFile = JArrayHelper::getValue($fileData, 'tmp_name');
     $uploadedName = JArrayHelper::getValue($fileData, 'name');
     $errorCode = JArrayHelper::getValue($fileData, 'error');
     $destination = JPath::clean($app->get("tmp_path")) . DIRECTORY_SEPARATOR . JFile::makeSafe($uploadedName);
     $file = new ITPrismFile();
     // Prepare size validator.
     $KB = 1024 * 1024;
     $fileSize = (int) $app->input->server->get('CONTENT_LENGTH');
     $mediaParams = JComponentHelper::getParams("com_media");
     /** @var $mediaParams Joomla\Registry\Registry */
     $uploadMaxSize = $mediaParams->get("upload_maxsize") * $KB;
     // Prepare size validator.
     $sizeValidator = new ITPrismFileValidatorSize($fileSize, $uploadMaxSize);
     // Prepare server validator.
     $serverValidator = new ITPrismFileValidatorServer($errorCode, array(UPLOAD_ERR_NO_FILE));
     $file->addValidator($sizeValidator);
     $file->addValidator($serverValidator);
     // Validate the file
     if (!$file->isValid()) {
         throw new RuntimeException($file->getError());
     }
     // Prepare uploader object.
     $uploader = new ITPrismFileUploaderLocal($uploadedFile);
     $uploader->setDestination($destination);
     // Upload the file
     $file->setUploader($uploader);
     $file->upload();
     $fileName = basename($destination);
     // Extract file if it is archive
     $ext = JString::strtolower(JFile::getExt($fileName));
     if (strcmp($ext, "zip") == 0) {
         $destFolder = JPath::clean($app->get("tmp_path")) . "/" . $type;
         if (is_dir($destFolder)) {
             JFolder::delete($destFolder);
         }
         $filePath = $this->extractFile($destination, $destFolder);
     } else {
         $filePath = $destination;
     }
     return $filePath;
 }
Example #26
0
 public function importFromFile(&$importFile)
 {
     $app = JFactory::getApplication();
     if (empty($importFile['name'])) {
         $app->enqueueMessage(JText::_('BROWSE_FILE'), 'notice');
         return false;
     }
     jimport('joomla.filesystem.file');
     $allowedFiles = array('csv', 'txt');
     $uploadFolder = rtrim(JPath::clean(html_entity_decode($this->config->get('uploadfolder'))), DS) . DS;
     if (strpos($uploadFolder, JPATH_ROOT) !== false) {
         $uploadFolder = str_replace(JPATH_ROOT, '', $uploadFolder);
     }
     $uploadFolder = ltrim($uploadFolder, '/');
     $uploadFolder = JPATH_ROOT . DS . $uploadFolder;
     $uploadPath = $uploadFolder;
     if (!is_dir($uploadPath)) {
         jimport('joomla.filesystem.folder');
         JFolder::create($uploadPath);
         $data = '<html><body bgcolor="#FFFFFF"></body></html>';
         JFile::write($uploadPath . 'index.html', $data);
     }
     if (!is_writable($uploadPath)) {
         @chmod($uploadPath, '0755');
         if (!is_writable($uploadPath)) {
             $app->enqueueMessage(JText::sprintf('WRITABLE_FOLDER', $uploadPath), 'notice');
         }
     }
     $attachment = new stdClass();
     $attachment->filename = strtolower(JFile::makeSafe($importFile['name']));
     $attachment->size = $importFile['size'];
     $attachment->extension = strtolower(substr($attachment->filename, strrpos($attachment->filename, '.') + 1));
     if (!in_array($attachment->extension, $allowedFiles)) {
         $app->enqueueMessage(JText::sprintf('ACCEPTED_TYPE', $attachment->extension, implode(',', $allowedFiles)), 'notice');
         return false;
     }
     if (!move_uploaded_file($importFile['tmp_name'], $uploadPath . $attachment->filename)) {
         if (!JFile::upload($importFile['tmp_name'], $uploadPath . $attachment->filename)) {
             $app->enqueueMessage(JText::sprintf('FAIL_UPLOAD', $importFile['tmp_name'], $uploadPath . $attachment->filename), 'error');
         }
     }
     hikaserial::increasePerf();
     $contentFile = file_get_contents($uploadPath . $attachment->filename);
     if (!$contentFile) {
         $app->enqueueMessage(JText::sprintf('FAIL_OPEN', $uploadPath . $attachment->filename), 'error');
         return false;
     }
     unlink($uploadPath . $attachment->filename);
     return $this->handleCsvContent($contentFile);
 }
Example #27
0
 function upload()
 {
     global $mainframe;
     // Check for request forgeries
     if (!JRequest::checkToken('request')) {
         // 401 Unauthorized
         return $this->end(401, 'Invalid Token');
     }
     // Check to see if uploading is enabled
     if ($mainframe->isSite() && !LinkrHelper::getParam('frontend_upload', '0')) {
         // 401 Unauthorized
         return $this->end(401, 'Uploading Disabled');
     }
     $this->file = JRequest::getVar('Filedata', '', 'files', 'array');
     $this->json = JRequest::getVar('format', 'html', '', 'cmd') == 'json';
     $this->returnURL = 'index.php?option=com_linkr&view=articles&tmpl=component';
     LinkrHelper::log('File::upload ' . $this->file['name']);
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Make the filename safe
     $this->file['name'] = strtolower(JFile::makeSafe($this->file['name']));
     if (empty($this->file['name'])) {
         LinkrHelper::log('Upload failed: empty filename ');
         return $this->end(400, 'bad request');
     }
     if (!$this->canUpload()) {
         return $this->end(415, 'Unsupported Media Type');
     }
     // Get full filename
     $model =& $this->getModel('articles');
     $paths = $model->fileInfo();
     $name = $paths['path'] . DS . $this->file['name'];
     // Check filename
     $name = JPath::clean($name);
     if (JFile::exists($name)) {
         // 409 Conflict
         LinkrHelper::log("Upload failed: file already exists ({$name})");
         return $this->end(409, 'File already exists');
     }
     // Uplaod
     if (!JFile::upload($this->file['tmp_name'], $name)) {
         // Is this a 400 bad request or 500 internal error?
         LinkrHelper::log("Upload failed: could not upload file ({$name})");
         return $this->end(500, 'Could not upload file');
     }
     // Upload complete
     LinkrHelper::log('File uploaded');
     $this->end(200, 'File uploaded!');
 }
Example #28
0
 public function prepare_fileupload($map_id, $mapimage)
 {
     $file = JRequest::getVar('file_upload2', null, 'files', 'array');
     $filename = JFile::makeSafe($file['name']);
     if ($filename != '') {
         $upload = $this->uploadmapfile($file, $map_id, $mapimage);
         if (!$upload) {
             return false;
             $this->setRedirect(JRoute::_('index.php?option=com_htraininglogs&view=session&layout=edit&sub_id=' . $sub_id, false));
         }
     } else {
         return true;
     }
 }
Example #29
0
 public static function createThumb($path, $width = 100, $height = 100, $crop = 2, $cachefolder = 'hgimages', $external = 0)
 {
     $myImage = new JImage();
     if (!$external) {
         $myImage->loadFile(JPATH_SITE . DS . $path);
     } else {
         $myImage->loadFile($path);
     }
     if ($myImage->isLoaded()) {
         // $filename = end(explode('/', $path));
         $filename = JFile::getName($path);
         $filefolder = substr(md5(self::getFolderPath($path)), 1, 10);
         $newfilename = $width . 'x' . $height . 'x' . $crop . '_' . $filefolder . '_' . JFile::makeSafe($filename);
         $hgimages = JPATH_CACHE . '/' . $cachefolder . '/';
         if (!JFolder::exists($hgimages)) {
             JFolder::create($hgimages);
         }
         $fileExists = JFile::exists($hgimages . $newfilename);
         if (!$fileExists) {
             switch ($crop) {
                 // Case for self::CROP
                 case 4:
                     $resizedImage = $myImage->crop($width, $height, null, null, true);
                     break;
                     // Case for self::CROP_RESIZE
                 // Case for self::CROP_RESIZE
                 case 5:
                     $resizedImage = $myImage->cropResize($width, $height, true);
                     break;
                 default:
                     $resizedImage = $myImage->resize($width, $height, true, $crop);
                     break;
             }
             $properties = $myImage->getImageFileProperties($path);
             $mime = $properties->mime;
             if ($mime == 'image/jpeg') {
                 $type = IMAGETYPE_JPEG;
             } elseif ($mime = 'image/png') {
                 $type = IMAGETYPE_PNG;
             } elseif ($mime = 'image/gif') {
                 $type = IMAGETYPE_GIF;
             }
             $resizedImage->toFile($hgimages . $newfilename, $type);
         }
         return $newfilename;
     } else {
         return "My file is not loaded";
     }
 }
Example #30
0
 /**
  * Deletes paths from the current path
  *
  * @param string $listFolder The image directory to delete a file from
  * @since 1.5
  */
 function delete()
 {
     global $mainframe;
     JRequest::checkToken('request') or jexit('Invalid Token');
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     // Get some data from the request
     $tmpl = JRequest::getCmd('tmpl');
     $paths = JRequest::getVar('rm', array(), '', 'array');
     $folder = JRequest::getVar('folder', '', '', 'path');
     // Initialize variables
     $msg = array();
     $ret = true;
     if (count($paths)) {
         foreach ($paths as $path) {
             if ($path !== JFile::makeSafe($path)) {
                 JError::raiseWarning(100, JText::_('Unable to delete:') . htmlspecialchars($path, ENT_COMPAT, 'UTF-8') . ' ' . JText::_('WARNDIRNAME'));
                 continue;
             }
             $fullPath = JPath::clean(COM_MEDIA_BASE . DS . $folder . DS . $path);
             if (is_file($fullPath)) {
                 $ret |= !JFile::delete($fullPath);
             } else {
                 if (is_dir($fullPath)) {
                     $files = JFolder::files($fullPath, '.', true);
                     $canDelete = true;
                     foreach ($files as $file) {
                         if ($file != 'index.html') {
                             $canDelete = false;
                         }
                     }
                     if ($canDelete) {
                         $ret |= !JFolder::delete($fullPath);
                     } else {
                         JError::raiseWarning(100, JText::_('Unable to delete:') . $fullPath . ' ' . JText::_('Not Empty!'));
                     }
                 }
             }
         }
     }
     if ($tmpl == 'component') {
         // We are inside the iframe
         $mainframe->redirect('index.php?option=com_media&view=mediaList&folder=' . $folder . '&tmpl=component');
     } else {
         $mainframe->redirect('index.php?option=com_media&folder=' . $folder);
     }
 }