Advertisement
Guest User

Untitled

a guest
May 4th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.30 KB | None | 0 0
  1. <?php
  2. $error = '';
  3. if((! (
  4.     isset($_FILES['file']) &&
  5.     isset($_POST['title']) &&
  6.     isset($_POST['type_upload']) &&
  7.     isset($_FILES['thumbnail']) &&
  8.     isset($_FILES['alt_1']) &&
  9.     isset($_FILES['alt_2']) &&
  10.     isset($_POST['description'])
  11.     )) ||
  12.     (! (
  13.     isset($_POST['scout_upload']) ||
  14.     isset($_POST['soldier_upload']) ||
  15.     isset($_POST['pyro_upload']) ||
  16.     isset($_POST['demoman_upload']) ||
  17.     isset($_POST['heavy_upload']) ||
  18.     isset($_POST['engineer_upload']) ||
  19.     isset($_POST['medic_upload']) ||
  20.     isset($_POST['sniper_upload']) ||
  21.     isset($_POST['spy_upload'])
  22.     ))
  23.     )
  24.     {
  25.             $error .= 'Not everything is filled in.';
  26.     }
  27.  
  28. $allowed_mod_types = array('zip','rar');
  29. $allowed_image_types = array('jpg','jpeg','png');
  30.  
  31. if(!in_array(file_ext($_FILES['file']['name']),$allowed_mod_types)) { $error .= '<br />File not zip or rar.'; }
  32. if(!in_array(file_ext($_FILES['thumbnail']['name']),$allowed_image_types)) { $error .= '<br />Thumbnail not jpg or png.'; }
  33. if(!in_array(file_ext($_FILES['alt_1']['name']),$allowed_image_types)) { $error .= '<br />Alternative image 1 not jpg or png.'; }
  34. if(!in_array(file_ext($_FILES['alt_2']['name']),$allowed_image_types)) { $error .= '<br />Alternative image 2 not jpg or png.'; }
  35.  
  36. die($error);
  37. //header('Location: submit.php'); //redirect to page
  38.  
  39. if($_FILES['file']['size'] > 5242880) { die("file too large"); }
  40.  
  41. list($w, $h, , )=getimagesize($_FILES['thumbnail']['tmp_name']); if($w != 165 || $h != 165) { die("wrong thumbnail image size"); }
  42.  
  43. function file_ext($filename) {
  44.     return end(explode(".", strtolower($filename)));
  45. }
  46.  
  47.  
  48. $server = 'localhost';
  49. $username = 'root';
  50. $password = '';
  51. $database = 'tf2emp';
  52. $link = new mysqli($server,$username,$password,$database);
  53.    
  54. $title = $link->real_escape_string($_POST['title']);
  55. $type_upload = $link->real_escape_string($_POST['type_upload']);
  56. $description = $link->real_escape_string($_POST['description']);
  57.  
  58. $scout = isset($_POST['scout_upload']) ? '1' : '0';
  59. $soldier = isset($_POST['soldier_upload']) ? '1' : '0';
  60. $pyro = isset($_POST['pyro_upload']) ? '1' : '0';
  61. $demoman = isset($_POST['demoman_upload']) ? '1' : '0';
  62. $heavy = isset($_POST['heavy_upload']) ? '1' : '0';
  63. $engineer = isset($_POST['engineer_upload']) ? '1' : '0';
  64. $medic = isset($_POST['medic_upload']) ? '1' : '0';
  65. $sniper = isset($_POST['sniper_upload']) ? '1' : '0';
  66. $spy = isset($_POST['spy_upload']) ? '1' : '0';
  67.  
  68. $file_dir = "files/mods/";
  69. $image_dir = "files/gallery_images/";
  70. $file_basename = $file_dir . basename($_FILES['file']['name']);
  71.  
  72. $mod_name = basename($_FILES['file']['name']);
  73. $mod_location = $file_dir . $mod_name;
  74. do { $mod_name = md5(rand().$mod_name) . '.' . file_ext($mod_location); $mod_location = $file_dir . $mod_name; } while ( file_exists($mod_location) );
  75. $thumb_name = basename($_FILES['thumbnail']['name']);
  76. $thumb_location = $image_dir . $thumb_name;
  77. do { $thumb_name = md5(rand().$thumb_name) . '.' . file_ext($thumb_location); $thumb_location = $image_dir . $thumb_name; } while ( file_exists($thumb_location) );
  78. $alt1_name = basename($_FILES['alt_1']['name']);
  79. $alt1_location = $image_dir . $alt1_name;
  80. do { $alt1_name = md5(rand().$alt1_name) . '.' . file_ext($alt1_location); $alt1_location = $image_dir . $alt1_name; } while( file_exists($alt1_location) );
  81. $alt2_name =  basename($_FILES['alt_1']['name']);
  82. $alt2_location = $image_dir . basename($_FILES['alt_2']['name']);
  83. do { $alt2_name = md5(rand().$alt2_name) . '.' .  file_ext($alt2_location); $alt2_location = $image_dir . $alt2_name; } while( file_exists($alt2_location) );
  84.  
  85. move_uploaded_file($_FILES['file']['tmp_name'], $mod_location);
  86. move_uploaded_file($_FILES['thumbnail']['tmp_name'], $thumb_location);
  87. move_uploaded_file($_FILES['alt_1']['tmp_name'], $alt1_location);
  88. move_uploaded_file($_FILES['alt_2']['tmp_name'], $alt2_location);
  89.  
  90. $sql = "INSERT INTO `tf2emp`.`mods` (`id`, `userid`, `timestamp`, `title`, `description`, `category`, `url`, `thumbnail`, `alt1`, `alt2`, `downloads`, `soldier`, `scout`, `pyro`, `demoman`, `heavy`, `engineer`, `medic`, `sniper`, `spy`, `featured`) VALUES (NULL, '-1', CURRENT_TIMESTAMP, '$title', '$description', '$type_upload', '$mod_name', '$thumb_name', '$alt1_name', '$alt2_name', '0', '$soldier', '$scout', '$pyro', '$demoman', '$heavy', '$engineer', '$medic', '$sniper', '$spy', '0')";
  91.  
  92. $link->query($sql);
  93. $link->close();
  94.  
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement