daily pastebin goal
46%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function uploadfile() {
  2.     JRequest::setVar('tmpl','component');
  3.     $db             =& JFactory::getDBO();
  4.     $session        = JFactory::getSession();
  5.     $config         = RSCommentsHelper::getConfig();
  6.     $file           = JRequest::getVar('file', null, 'files', 'array');
  7.     $IdComment      = $session->get('com_rscomments.IdComment','');
  8.     $root           = JRequest::getVar('root');
  9.     $url_captcha    = JRequest::getVar('url_captcha');
  10.  
  11.     if (!$config->enable_upload) return;
  12.  
  13.     jimport('joomla.filesystem.file');
  14.     $uploadFolder = JPATH_SITE.DS.'components'.DS.'com_rscomments'.DS.'assets'.DS.'files'.DS;
  15.  
  16.     $valid                  = true;
  17.     $successfully_uploaded  = '';
  18.     $msg                    = '';
  19.  
  20.     if (!empty($file) && empty($file['error']))
  21.     {
  22.         $src        = $file['tmp_name'];
  23.         $filename   = JFile::makeSafe($file['name']);
  24.         $ext        = strtolower(JFile::getExt($filename));
  25.         $filename   = JFile::stripExt($filename);
  26.         // if we edit the file and upload another file
  27.  
  28.         $extensions = strtolower($config->allowed_extensions);
  29.         $extensions = str_replace("r",'',$extensions);
  30.         $extensions = explode("n",$extensions);
  31.  
  32.         if (!empty($extensions) && is_array($extensions) && in_array($ext,$extensions))
  33.         {
  34.             $max_size = 1024 * 1024;
  35.             $set_size = 1;
  36.             if ($max_size > $file['size'])
  37.             {
  38.                 while (JFile::exists($uploadFolder.$filename.'.'. $ext))
  39.                     $filename .= rand(10, 99);
  40.  
  41.                 $dest = $uploadFolder.$filename.'.'.$ext;
  42.  
  43.                 // this is the part where I start adding code
  44.  
  45.                 // Get current sizes
  46.                 list ($startWidth,$startHeight) = getimagesize($src);
  47.  
  48.                 // conditional statement
  49.                 if ($startWidth > 500) {
  50.  
  51.                 // Load image
  52.                 $src_to_resize = imagecreatefromjpeg($src);
  53.  
  54.                 // setting new width and calculate new height
  55.                 $newWidth = 500;
  56.                 $newHeight = (int) ($startHeight * (500 / $startWidth));
  57.  
  58.                 // create a new temporary image
  59.                 $tmp = imagecreatetruecolor($newWidth, $newHeight);
  60.  
  61.                 // Resize
  62.                 imagecopyresized($tmp, $src_to_resize, 0, 0, 0, 0, $newWidth, $newHeight, $startWidth, $startHeight);
  63.  
  64.                 // Output
  65.                 imagejpeg($tmp,$src_to_resize,70);
  66.  
  67.                 JFile::upload($src_to_resize, $dest);
  68.  
  69.                 // echo's to see what's going on
  70.                 $msg  = 'n$startWidth = '.$startWidth;
  71.                 $msg .= 'n$startHeight = '.$startHeight;
  72.                 $msg .= 'n$newWidth = '.$newWidth;
  73.                 $msg .= 'n$newHeight = '.$newHeight;
  74.  
  75.                 $msg .= 'n$src inside added code = '.$src;
  76.                 $msg .= 'n$src_to_resize = '.$src_to_resize;
  77.                 $msg .= 'n$tmp inside added code = '.$tmp;
  78.                 $msg .= 'n$dest inside added code = '.$dest;
  79.                 }
  80.  
  81.                 // from this point it's the original code
  82.                 // it was originally not between this else-statement
  83.  
  84.                 else {
  85.                    JFile::upload($src, $dest);
  86.                 }
  87.  
  88.                 $db->setQuery("INSERT INTO #__rscomments_comments SET `file` = '".$db->getEscaped($filename.'.'.$ext)."'");
  89.                 $db->query();
  90.                 $IdComment = $db->insertid();
  91.  
  92.                 $session->set('com_rscomments.IdComment', $IdComment);
  93.                 $valid = true;
  94.  
  95.             } else { $msg = JText::sprintf('RSC_ERROR_SIZE',$set_size); $valid = false; }
  96.         } else { $msg = JText::sprintf('RSC_ERROR_EXTENSION',implode(', ',$extensions)); $valid = false; }
  97.     }
  98.  
  99.     echo '<form name="frameform" id="frameform" action="'.JRoute::_('index.php?option=com_rscomments&task=uploadfile').'" method="post" enctype="multipart/form-data">';
  100.     echo '<input type="file" name="file" />'.$successfully_uploaded;
  101.     echo '<input type="hidden" name="root" id="root" value="" />';
  102.     echo '<input type="hidden" name="url_captcha" id="url_captcha" value="" />';
  103.     echo '</form>';
  104.  
  105.     if ($valid) {
  106.         echo "<script type="text/javascript">
  107.             alert('".$msg."');
  108.             window.parent.rsc_save('".$root."','".$url_captcha."');
  109.         </script>";
  110.     } else {
  111.         if($msg != ''){
  112.         echo "
  113.         <script type="text/javascript">
  114.             alert('".$msg."');
  115.  
  116.             // reload captcha
  117.             sign = ('".$url_captcha."'.indexOf('?') == -1) ? '?' : '&';
  118.             if(window.parent.document.getElementById('submit_captcha_image')) window.parent.document.getElementById('submit_captcha_image').src = '".$url_captcha."'+sign+'sid=' + Math.random();
  119.  
  120.             // reload recaptcha
  121.             if(window.parent.document.getElementById('rsc_recaptcha'))
  122.             {
  123.                 window.parent.document.getElementById('recaptcha_response_field').value = '';
  124.                 window.parent.Recaptcha.reload();
  125.             }
  126.         </script>";
  127.         }
  128.     }
  129.     exit();
  130. }
  131.    
  132. $startWidth = 600
  133.     $startHeight = 183
  134.     $newWidth = 500
  135.     $newHeight = 152
  136.     $src inside added code = /tmp/phpi108VE
  137.     $src_to_resize inside added code = Resource id #126
  138.     $tmp inside added code = Resource id #127
  139.     $dest inside added code = serverpath/test600px55.jpg
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top