What I'm trying to do is make it so that when a user uploads a file, it uses a variable's value as the file name, rather than the actual file's name, and then saves it as that name.

So, for example, if the variable is `$variable = "50";`, how can I save the file as `50.png` (or whatever extension they upload it in)?

Here's my code:

```
$variable = $_POST['id']; // taken from the form

$whitelist = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);

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"] < 2097152) && in_array($extension, $whitelist)) {
  if($_FILES["file"]["error"] > 0) {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
  } else {
    echo "File name: " . $_FILES["file"][$user_id];

    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: " . "upload/" . $_FILES["file"]["name"];
    }
  }
} else {
  echo "Invalid file";
}

```

Please help.