我想允许用户上传 txt、doc 或 pdf 格式的文件。我已经为此编写了以下代码。
if ((($_FILES["uploaded"]["type"] == "text/plain")
|| ($_FILES["uploaded"]["type"] == "application/pdf")
|| ($_FILES["uploaded"]["type"] == "application/doc"))
&& ($_FILES["uploaded"]["size"] < 50000))
{
if ($_FILES["uploaded"]["error"] > 0)
{
echo "Error: " . $_FILES["uploaded"]["error"] . "<br />";
}
else
{
$target = "upload/";
$target = $target . basename($_FILES['uploaded']['name']);
$ok = 1;
if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file " . basename($_FILES['uploadedfile']['name']) . " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
}
else
{
echo "Invalid file";
}
但是这段代码不起作用。无论如何,它总是显示无效文件。可能是什么问题?