PHP随机重命名照片

I am using this code:

<?php

$ran = rand () ;
$ran2 = $ran.".";

$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "filer.SITEHERE.com/upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file or service down";
  echo "It must be an image to be uploaded.";
  }
?>

Is there any way i can get ran2 to be the filename instead of the original name? Sorry, i am a beginner at PHP and could not find something that would work. I would like to stick mostly to this script or atleast make it so they can only upload images up to a certain size.

Edit: Removed site name.

You're not using $ran2 at all. Follow Ryan's example, but add $extension, since it looks like you had it ready to be appended..

So:

move_uploaded_file($_FILES["file"]["tmp_name"], "/upload/" . $ran2 . $extension);

Just change the second parameter to move_uploaded_file, I also see that you don't add an extension, so this should add it as well:

// Don't forget to add the extension
$extension = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $ran2 . $extension);