好吧,这是我的代码,但是当我尝试上传 doc 文件时,响应是“无效文件”.....非常感谢。顺便说一句,我的第二个问题涉及将上传文件重命名为所需格式“实际时间 + 原始标题”$date。
<?php
$datum = Date("j/m/Y/H/i/s", Time());
echo($date);
$allowedExts = array("doc");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "application/msword"))
&& ($_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("uploaded_papers/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploaded_papers/" . $_FILES["file"]["name"]);
echo "Stored in: " . "uploaded_papers/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>