Guest User

Untitled

a guest
Jan 30th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. <?php
  2. function random($length) {
  3. $random = "";
  4. $x = 0;
  5.  
  6. while($x < $length){
  7. $part = rand(1, 3);
  8. if ($part == 1){
  9. $a = 48;
  10. $b = 57;
  11. }
  12. if ($part == 2){
  13. $a = 65;
  14. $b = 90;
  15. }
  16. if ($part == 3){
  17. $a = 97;
  18. $b = 122;
  19. }
  20.  
  21. $code_part = chr(rand($a, $b));//letter generation
  22. //$code_part = chr(rand(48, 122)); letters + punctuation generation
  23. $x = $x + 1;
  24. $random .= $code_part;
  25. }
  26.  
  27. return $random;
  28. }
  29.  
  30. if (isset($_POST['submit'])) {
  31. if (isset($_FILES['file']) && !empty($_FILES['file']['name'])) {
  32. $file = $_FILES['file']['name'];
  33. $extention = pathinfo($file, PATHINFO_EXTENSION);
  34. $file_new = random(5) . "." . $extention;
  35.  
  36. $temp = $_FILES['file']['tmp_name'];
  37. $filesize = $_FILES['file']['size'] / 1024 / 1024;
  38. $size = number_format($filesize, 3);
  39.  
  40. if (in_array(strtolower($extention), array("png","ico","jpeg","jpg","gif"))) {
  41. if (move_uploaded_file($temp, "../images/news/" . $file_new)) {
  42. $file_new = urlencode($file_new);
  43. $file = urlencode($file);
  44. $upload_e = false;
  45. } else {
  46. $upload_e = "Failed to upload.";
  47. }
  48. } else {
  49. $upload_e = "You can't upload that file type!";
  50. }
  51. } else {
  52. $upload_e = "";
  53. }
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment