我有此代码上传 .png 图像。我将在哪里更改代码以将文件名更改为现有的 $_POST['var_name'] 也用于上传表单?
<?php
$directory = uploaded_labels; // Name of directory that file is being saved to
$var_name = $_POST["var_name"]; // Variable name from form to change the name to
$allowedExts = array("png"); // Allowed extensions
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& 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("$directory/" . $_FILES["file"] ["name"]))
{
echo $_FILES["file"] ["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
$directory."/" . $_FILES["file"] ["name"]);
echo "Stored in: " . $directory."/" .$_FILES["file"] ["name"];
}
}
}
else
{
echo "Invalid file";
}
?>