Exemplo n.º 1
0
 public function dfgsdfguploadmapfile($file, $map_id, $mapimage)
 {
     $app = JFactory::getApplication();
     $model = $this->getModel();
     $user = JFactory::getUser();
     $filename = HTraininglogsHelper::sanitize($file['name']);
     //JFile::makeSafe($file['name']);
     $src = $file['tmp_name'];
     $dir = JPATH_SITE . DS . 'images' . DS . 'htraininglogs' . DS . $user->id . DS . 'maps' . DS;
     $dir_thumb = $dir . 'thumbs' . DS;
     $dest = $dir . $filename;
     if (!file_exists($dest) || $filename == $mapimage) {
         if (JFile::upload($src, $dest)) {
             $file_ext = strtolower(JFile::getExt($filename));
             $thumbnail = $dir_thumb . $filename;
             list($width, $height) = getimagesize($dir . $filename);
             $ratio = $width / $height;
             $thumb_height = 100;
             $thumb_width = 300;
             //intval($thumb_height*$ratio);
             $thumb_create = imagecreatetruecolor($thumb_width, $thumb_height);
             //echo $thumbnail.$dir.$filename;exit;
             switch ($file_ext) {
                 case 'jpg':
                     $source = imagecreatefromjpeg($dir . $filename);
                     break;
                 case 'jpeg':
                     $source = imagecreatefromjpeg($dir . $filename);
                     break;
                 case 'png':
                     $source = imagecreatefrompng($dir . $filename);
                     break;
                 case 'gif':
                     $source = imagecreatefromgif($dir . $filename);
                     break;
                 default:
                     $source = imagecreatefromjpeg($dir . $filename);
             }
             //imagecopyresized($thumb_create,$source,0,0,0,0,$thumb_width,$thumb_height,$width,$height);
             imagecopyresized($thumb_create, $source, 0, 0, (int) $width / 2 - $thumb_width, (int) $height / 2 - $thumb_height, $thumb_width, $thumb_height, 2 * $thumb_width, 2 * $thumb_height);
             switch ($file_ext) {
                 case 'jpg':
                 case 'jpeg':
                     imagejpeg($thumb_create, $thumbnail, 100);
                     break;
                 case 'png':
                     imagepng($thumb_create, $thumbnail, 100);
                     break;
                 case 'gif':
                     imagegif($thumb_create, $thumbnail, 100);
                     break;
                 default:
                     imagejpeg($thumb_create, $thumbnail, 100);
             }
             if ($model->storeimage($filename, $map_id)) {
                 return true;
             }
         }
     } else {
         $app->enqueueMessage(JText::sprintf('COM_HTRAININGLOGS_FILEEXISTS', $filename), 'error');
         return false;
     }
 }
Exemplo n.º 2
0
 public static function uploadmediafile($file, $currentfilename, $destdir, $center, $thumb_height)
 {
     $app = JFactory::getApplication();
     $filename = HTraininglogsHelper::sanitize($file['name']);
     //JFile::makeSafe($file['name']);HTraininglogsHelper::
     $src = $file['tmp_name'];
     $dest = $destdir . $filename;
     $dir_thumb = $destdir . 'thumbs/';
     if (!file_exists($dest) || $filename == $currentfilename) {
         if (JFile::upload($src, $dest)) {
             HTraininglogsHelper::create_thumb($destdir, $filename, $center, $dir_thumb, $thumb_height, NULL);
             if (!$center) {
                 $dir_thumb = $destdir . 'bigthumbs/';
                 HTraininglogsHelper::create_thumb($destdir, $filename, $center, $dir_thumb, NULL, 750);
             }
             return $filename;
         } else {
             $app->enqueueMessage(JText::sprintf('COM_HTRAININGLOGS_FILEUPLOADFAILED', $filename), 'error');
             return false;
         }
     } else {
         $app->enqueueMessage(JText::sprintf('COM_HTRAININGLOGS_FILEEXISTS', $filename), 'error');
         return false;
     }
 }