I am new to PHP and I am trying to get this code to rename a file and save it in the subdirectory. But I need it to keep the extension. Please Help me!
<?php
$allowedExts = array("txt", "dxf","DXF" , "pdf", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "applicatio n/octet-stream")
|| ($_FILES["file"]["type"] == "applicatio n/pdf")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($exten sion, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo ".tmpFiles: " . $_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(". tmpFiles/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_f ile($_FILES["file"]["tmp_name"],
".tmpFiles/" . $_FILES["file"]["name"]);
echo "Stored in: " . ".tmpFiles/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
include('list.p hp');
?>
Thanks in advance for you help
<?php
$allowedExts = array("txt", "dxf","DXF" , "pdf", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "applicatio n/octet-stream")
|| ($_FILES["file"]["type"] == "applicatio n/pdf")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($exten sion, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo ".tmpFiles: " . $_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(". tmpFiles/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_f ile($_FILES["file"]["tmp_name"],
".tmpFiles/" . $_FILES["file"]["name"]);
echo "Stored in: " . ".tmpFiles/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
include('list.p hp');
?>
Thanks in advance for you help
Comment