Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2. if (isset($_FILES["avatar"]["name"]) && $_FILES["avatar"]["tmp_name"] != ""){
  3. $fileName = $_FILES["avatar"]["name"];
  4. $fileTmpLoc = $_FILES["avatar"]["tmp_name"];
  5. $fileType = $_FILES["avatar"]["type"];
  6. $fileSize = $_FILES["avatar"]["size"];
  7. $fileErrorMsg = $_FILES["avatar"]["error"];
  8. $kaboom = explode(".", $fileName);
  9. $fileExt = end($kaboom);
  10. list($width, $height) = getimagesize($fileTmpLoc);
  11. if($width < 10 || $height < 10){
  12. header("location: ../message.php?msg=ERROR: That image has no dimensions");
  13. exit();
  14. }
  15. $db_file_name = rand(100000000000,999999999999).".".$fileExt;
  16. if($fileSize > 2048576) {
  17. header("location: ../message.php?msg=ERROR: Your image file was larger than 2MB");
  18. exit();
  19. } else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
  20. header("location: ../message.php?msg=ERROR: Your image file was not jpg, gif or png type");
  21. exit();
  22. } else if ($fileErrorMsg == 1) {
  23. header("location: ../message.php?msg=ERROR: An unknown error occurred");
  24. exit();
  25. }
  26. $sql = "SELECT avatar FROM users WHERE username='$log_username' LIMIT 1";
  27. $query = mysqli_query($db_conx, $sql);
  28. $row = mysqli_fetch_row($query);
  29. $avatar = $row[0];
  30. if($avatar != ""){
  31. $picurl = "../user/$log_username/$avatar";
  32. if (file_exists($picurl)) { unlink($picurl); }
  33. }
  34. $moveResult = move_uploaded_file($fileTmpLoc, "../user/$log_username/$db_file_name");
  35. if ($moveResult != true) {
  36. header("location: ../message.php?msg=ERROR: File upload failed");
  37. exit();
  38. }
  39. include_once("../php_includes/image_resize.php");
  40. $target_file = "../user/$log_username/$db_file_name";
  41. $resized_file = "../user/$log_username/$db_file_name";
  42. $wmax = 200;
  43. $hmax = 300;
  44. img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
  45. $sql = "UPDATE users SET avatar='$db_file_name' WHERE username='$log_username' LIMIT 1";
  46. $query = mysqli_query($db_conx, $sql);
  47. mysqli_close($db_conx);
  48. header("location: ../user.php?u=$log_username");
  49. exit();
  50. }
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement