Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.88 KB | None | 0 0
  1. case 'rank' :
  2.         $template->set_filenames(array(
  3.         'body' => 'store/rank.html',
  4.         ));
  5.                 // Move the file
  6.                 if ( isset($_POST["submit"]) && $row['user_points'] >= 300 && file_exists($_FILES['rank']['tmp_name']) )
  7.                 {
  8.                         // Where the file is going to be placed
  9.                         $rankfile = $row['user_id'] . "." . findexts($_FILES['rank']['name']);
  10.                         $target_path = "images/ranks/";
  11.                         $target_path = $target_path . $rankfile;
  12.                         // Lets make sure we don't get hacked.
  13.                         // Trust a Stranger
  14.                         $wrongtype = false;
  15.                         // First By Checking that it is an image
  16.                         if ( $FileExt = "jpg")
  17.                         {
  18.                             $wrongtype = false;
  19.                         }
  20.                         else if ( $FileExt = "jpeg")
  21.                         {
  22.                             $wrongtype = false;
  23.                         }
  24.                         else if ( $FileExt = "png")
  25.                         {
  26.                             $wrongtype = false;
  27.                         }
  28.                         else if ( $FileExt = "gif")
  29.                         {
  30.                             $wrongtype = false;
  31.                         }
  32.                         else if ( $FileExt = "bmp")
  33.                         {
  34.                             $wrongtype = false;
  35.                         }
  36.                         else
  37.                         {
  38.                             $wrongtype = true;
  39.                         }
  40.                         // Then checking the filesize, it only need to be small
  41.                         if($_FILES['rank']['size']>5242880)
  42.                         {
  43.                             $toobig = true;
  44.                         }
  45.                         else
  46.                         {
  47.                             $toobig = false;
  48.                         }
  49.                         // Then checking the image size.
  50.                         $imagesize = getimagesize($_FILES['rank']['tmp_name']);
  51.                         $width = false;
  52.                         $height = false;
  53.                         if ($imagesize[0] > 110)
  54.                         {
  55.                             $width= true;
  56.                         }
  57.                         if ($imagesize[1] > 40)
  58.                         {
  59.                             $height = true;
  60.                         }
  61.                         // array 0 = width and 1 = hieght
  62.                         //Start the move
  63.                         if ( !$wrongtype && !$toobig && !$width && !$height )
  64.                         {
  65.                             if(move_uploaded_file($_FILES['rank']['tmp_name'], $target_path))
  66.                             {
  67.                                 // testing Stuffs
  68.                                 $template->assign_vars(array(
  69.                                     'ERROR' => $FileExts,
  70.                                 ));
  71.                                
  72.                                 // Lets put the rank into the database
  73.                                 $sql_ary = array(
  74.                                     'rank_title'    => '',
  75.                                     'rank_min'        => 0,
  76.                                     'rank_special'    => 1,
  77.                                     'rank_image'     => $rankfile,
  78.                                 );
  79.    
  80.                                 $sql = 'INSERT INTO ' . RANKS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
  81.                                 $db->sql_query($sql);
  82.                                
  83.                                 // And then Take it back out again.
  84.                                 $sql = 'SELECT rank_id
  85.                                         FROM ' . RANKS_TABLE . '
  86.                                         WHERE rank_image = 1660.jpg';
  87.                                         $result = $db->sql_query($sql);
  88.                                         $rankid = $db->sql_fetchrow('rank_id');
  89.                                        
  90.                                 // Now Lets make that rank the user's rank
  91.                                 $sql_ary = array(
  92.                                     'user_rank'    => $rankid,
  93.                                 );
  94.                                
  95.    
  96.                             $sql = 'UPDATE ' . USERS_TABLE . '
  97.                             SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
  98.                             WHERE user_id = ' . $user->data['user_id'];
  99.                             $db->sql_query($sql);
  100.                            
  101.                             }
  102.                             else
  103.                             {
  104.                             $template->assign_vars(array(
  105.                                     'ERROR' => "There was an error uploading the file, please try again!",
  106.                                     ));
  107.                             }
  108.                         }
  109.                         else if ( $wrongtype )
  110.                         {
  111.                             $template->assign_vars(array(
  112.                                 'ERROR' => "Only .jpeg, .jpg, .png, .gif and .bmp filetypes allowed",
  113.                             ));
  114.                         }
  115.                         else if ( $toobig )
  116.                         {
  117.                             $template->assign_vars(array(
  118.                                 'ERROR' => "Your image is too big, please choose a Smaller image",
  119.                             ));
  120.                         }
  121.                 }
  122.                 else if ( $row['user_points'] < 300 )
  123.                 {
  124.                     redirect(append_sid("{$phpbb_root_path}store.$phpEx",'mode=nofunds'));
  125.                 }
  126.                 else if ( !file_exists($_FILES['rank']['tmp_name']))
  127.                 {
  128.                     $template->assign_vars(array(
  129.                         'ERROR' => 'Please Select a File to Upload',
  130.                     ));
  131.                 }
  132.                 if (isset($_POST["cancel"]))
  133.                 {
  134.                     redirect(append_sid("{$phpbb_root_path}store.$phpEx"));
  135.                 }
  136.         break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement