Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.33 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting(0);
  4. $host = "localhost";
  5. $username = "toxxicc_fake";
  6. $password = "fake";
  7. $db_name = "toxxicc_forum";
  8. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  9. mysql_select_db("$db_name")or die("cannot select DB");
  10. if(!isset($_POST['board']))
  11. {
  12.  echo "Error! <a href=index.php>Return to abyxChan?</a>";
  13.  exit;
  14. }
  15. if($_POST['post'] == "")
  16. {
  17.  echo "Error! Post needs contents! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  18.  exit;
  19. }
  20.  
  21. define ("MAX_SIZE","5120");
  22. function getExtension($str) {
  23.          $i = strrpos($str,".");
  24.          if (!$i) { return ""; }
  25.          $l = strlen($str) - $i;
  26.          $ext = substr($str,$i+1,$l);
  27.          return $ext;
  28. }
  29. $errors=0;
  30. $image = $_FILES['image']['name'];
  31. if ($image)
  32. {
  33.  $filename = stripslashes($_FILES['image']['name']);
  34.  $extension = getExtension($filename);
  35.  $extension = strtolower($extension);
  36.  if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
  37.  {
  38.   echo "Error! Bad extension! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  39.   $errors=1;
  40.  }
  41.  else
  42.  {
  43.   $size=filesize($_FILES['image']['tmp_name']);
  44.   if ($size > MAX_SIZE*1024)
  45.   {
  46.    echo "Error! Size limit exceeded! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  47.    $errors=1;
  48.   }
  49.   $image_name=time().'.'.$extension;
  50.   $newname="img/".$image_name;
  51.   $copied = copy($_FILES['image']['tmp_name'], $newname);
  52.  
  53.   include('thumb.php');
  54.   if($_POST['name'] == "")
  55.   {
  56.    $name = "Anonymous";
  57.   }
  58.   else
  59.   {
  60.    $name = $_POST['name'];
  61.    $name = str_replace (" ", "", $name);
  62.    $name = htmlspecialchars($name, ENT_QUOTES);
  63.    $_SESSION['name'] = $name;
  64.   }
  65.   list($name,$trip) = explode("#", $name);
  66.   if($trip != "")
  67.   {
  68.    $trip = mb_convert_encoding($trip,"SJIS");
  69.    $salt = substr($trip."H.",1,2);
  70.    $salt = ereg_replace("[^\.-z]",".",$salt);
  71.    $salt = strtr($salt,":;<=>?@[\\]^_`","ABCDEFGabcdef");
  72.    $trip = substr(crypt($trip,$salt),-10)."";
  73.    $trip = mb_convert_encoding($trip,"UTF-8");
  74.   }
  75.   $_SESSION['email'] = $_POST['email'];
  76.   $email = htmlspecialchars($_POST['email'], ENT_QUOTES);
  77.   $subject = htmlspecialchars($_POST['subject'], ENT_QUOTES);
  78.   $post = htmlspecialchars($_POST['post'], ENT_QUOTES);
  79.   $post = wordwrap($post, 50, "\n", true);
  80.   $post = nl2br($post);
  81.  
  82.   $board = $_POST['board'];
  83.   $date = date("m/d/y(D) G:i");
  84.   $ip = $_SERVER['REMOTE_ADDR'];
  85.   $file = $image_name;
  86.   $bump = time();
  87.   $ismod = 0;
  88.   if(isset($_SESSION['admin']))
  89.   {
  90.    $ismod = 2;
  91.   }
  92.   if(isset($_SESSION['moderator']))
  93.   {
  94.    if($_SESSION['moderator'] == $board || $_SESSION['moderator'] == "global")
  95.    {
  96.     $ismod = 1;
  97.    }
  98.   }
  99.  
  100.   $pathfile = "img/". $file;
  101.   $filehash = md5_file($pathfile);
  102.   $result = mysql_query("SELECT * FROM posts") or die(mysql_error());
  103.   while($row = mysql_fetch_array( $result ))
  104.   {
  105.    if($filehash == $row['filehash'])
  106.    {
  107.     echo "Hash: ". $filehash ."<br />";
  108.     echo "Existing Hash: ". $row['filehash'] ."<br />";
  109.     echo "Duplicate file detected! <a href=index.php>Return?</a>";
  110.     unlink('img/'.$file);
  111.     unlink('img/thumbs/t'.$file);
  112.     exit;
  113.    }
  114.   }
  115.   $result = mysql_query("SELECT * FROM replies") or die(mysql_error());
  116.   while($row = mysql_fetch_array( $result ))
  117.   {
  118.    if($filehash == $row['filehash'])
  119.    {
  120.     echo "Hash: ". $filehash ."<br />";
  121.     echo "Existing Hash: ". $row['filehash'] ."<br />";
  122.     echo "Duplicate file detected! <a href=index.php>Return?</a>";
  123.     unlink('img/'.$file);
  124.     unlink('img/thumbs/t'.$file);
  125.     exit;
  126.    }
  127.   }
  128.  
  129.   mysql_query("INSERT INTO posts (board, date, author, trip, file, ip, email, subject, post, bump, replies, ismod, filehash) VALUES('$board', '$date', '$name', '$trip', '$file', '$ip', '$email', '$subject', '$post', '$bump', '0', '$ismod', '$filehash') ") or die(mysql_error());  
  130.  
  131.   if (!$copied)
  132.   {
  133.    echo "Error! Image could not be uploaded! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  134.    $errors=1;
  135.   }
  136.  }
  137. }
  138. else
  139. {
  140.  echo "Error! No image selected! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  141.  $errors=1;
  142. }
  143. if(!$errors)
  144. {
  145.  echo "Image upload successful! <a href=index.php?board=". $_POST['board'] .">Return to abyxChan?</a>";
  146. }
  147. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement