function uploadFile()
 {
     global $mainframe;
     $fieldName = 'upload_file';
     $dir = JPATH_SITE . DS . $this->config['root_folder'] . DS . $this->current_folder . DS;
     $accept = 'image/jpeg,image/png,image/gif,application/zip';
     $max_upload_size = 1024 * 1024 * $this->config['max_upload_size'];
     // Mb
     $array = custom_uploadFile($fieldName, $dir, $accept, $max_upload_size);
     if ($array[2] == 'application/zip') {
         // Process zip archive
         jimport('joomla.filesystem.archive');
         if (!JArchive::extract($dir . $array[0], $dir)) {
             JError::raiseError(500, _IMAGEBROWSER_ERROR_EXTRACT_ARCHIVE);
         }
         // Delete zip file after its been extracted
         unlink($dir . $array[0]);
     } else {
         // Process image
         $img_size = getimagesize($dir . $array[0]);
         if ($img_size[0] > $this->config['max_width'] || $img_size[1] > $this->config['max_height']) {
             // Instantiate image class used for resizing thumb - inc/image.class.php
             $image = new imageBrowserImage();
             // Create thumbnail
             $resize_image = $image->resize_image($dir . $array[0], $dir . $array[0], $this->config['max_width'], $this->config['max_height'], $this->config['imgcomp']);
             if ($resize_image === true) {
                 JError::raiseNotice(500, _IMAGEBROWSER_RESIZE_OK);
             } else {
                 JError::raise(2, 500, _IMAGEBROWSER_RESIZE_ERROR, '', false);
             }
         }
         // Generate thumbnail in thumb folder
         $this->generateThumb($array[0]);
     }
     $mainframe->redirect('index.php?option=' . $this->option . '&folder=' . $this->current_folder);
 }
Exemplo n.º 2
0
 /**
  * logic for uploading an image
  *
  * @access public
  * @return void
  * @since 0.9
  */
 function uploadimage()
 {
     global $mainframe, $tgconf;
     // Check for request forgeries
     JRequest::checkToken() or die('Invalid Token');
     $post = JRequest::get('post');
     $file = JRequest::getVar('userfile', '', 'files', 'array');
     $task = JRequest::getVar('task');
     //		$filename 	= JRequest::getVar( 'filename', '', 'text', 'array' );
     $folder = JRequest::getVar('folder');
     // Set FTP credentials, if given
     jimport('joomla.client.helper');
     JClientHelper::setCredentialsFromRequest('ftp');
     //set the target directory
     if ($task == 'galleryupload') {
         $base_Dir = HOTELGUIDE_MEDIA_GALLERY . DS . $folder . DS . 'album' . DS;
         if (!file_exists($base_Dir)) {
             mkdir($base_Dir, 0755);
         }
         $resize_Dir = HOTELGUIDE_MEDIA_GALLERY . DS . $folder . DS . 'resize' . DS;
         if (!file_exists($resize_Dir)) {
             mkdir($resize_Dir, 0755);
         }
         $thumb_Dir = HOTELGUIDE_MEDIA_GALLERY . DS . $folder . DS . 'thumb' . DS;
         if (!file_exists($thumb_Dir)) {
             mkdir($thumb_Dir, 0755);
         }
     } else {
         if ($task == 'introimgup') {
             $base_Dir = JPATH_SITE . DS . 'images' . DS . 'golfcourseguide' . DS . 'intro' . DS;
         }
     }
     //do we have an upload?
     if (empty($file['name'])) {
         echo "<script> alert('" . JText::_('IMAGE EMPTY') . "'); window.history.go(-1); </script>\n";
         $mainframe->close();
     }
     //check the image
     $check = HGImage::check($file, $tgconf);
     $imagefile = array();
     $imagefile = $_FILES['userfile'];
     $filepath = $base_Dir . $file['name'];
     $accept = 'image/jpeg,image/png,image/gif';
     $max_upload_size = 1024 * 1024 * $tgconf->tg_max_upload_size;
     $array = custom_uploadFile($imagefile, $file['name'], $base_Dir, $accept, $max_upload_size);
     $img_size = getimagesize($base_Dir . $array[0]);
     $where = 'gallery';
     //
     if ($img_size[0] > $tgconf->tg_city_width || $img_size[1] > $tgconf->tg_city_width) {
         $image = new imageBrowserImage();
         $resize_image = $image->resize_image($base_Dir . $array[0], $resize_Dir . $array[0], 120, 120, 10);
         if ($resize_image === true) {
             JError::raiseNotice(500, GALLERY_RESIZE_OK);
         } else {
             JError::raise(2, 500, GALLERY_RESIZE_ERROR, '', false);
         }
     }
     /*	
     		//upload the image
     		if (!JFile::upload($file['tmp_name'], $filepath)) {
     			echo "<script> alert('".JText::_( 'UPLOAD FAILED' )."'); window.history.go(-1); </script>\n";
     			$mainframe->close();
     
     		} else {
     			echo "<script> alert('".JText::_( 'UPLOAD COMPLETE' )."'); window.history.go(-1); window.parent.elSelectHotelImage('$filename', '$filename'); </script>\n";
     			$mainframe->close();
     		}
     */
     $model =& $this->getModel('imagehandler');
     if ($model->store($post)) {
         $link = 'index.php?option=com_hotelguide&view=imagehandler';
         $msg = JText::_('Data Saved!');
     } else {
         $link = 'index.php?option=com_hotelguide&view=imagehandler';
         $msg = JText::_('Error Saving Data');
     }
     //		$this->setRedirect($link, $msg);
 }