我有一个上传文件的脚本。它检查mime类型(应该是音频文件),然后上传它。该类型似乎被识别,但它给出了“无效文件”输出。我错过了一些明显的东西吗?
Upload: songname.mp3
Type: audio/mpeg
Size: 4.5997314453125 MB
Invalid file
脚本的一部分:
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / (1024*1024)) . " MB<br>";
}
$allowedExts = array("gif", "jpeg", "jpg", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "audio/mpeg")
|| ($_FILES["file"]["type"] == "audio/x-mpeg")
|| ($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/x-mp3")
|| ($_FILES["file"]["type"] == "audio/mpeg3")
|| ($_FILES["file"]["type"] == "audio/x-mpeg3")
|| ($_FILES["file"]["type"] == "audio/mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpg")
|| ($_FILES["file"]["type"] == "audio/x-mpegaudio")
|| ($_FILES["file"]["type"] == "audio/wav")
|| ($_FILES["file"]["type"] == "audio/x-wav")
|| ($_FILES["file"]["type"] == "audio/ogg"))
&& ($_FILES["file"]["size"] < 20000000)
&& in_array($extension, $allowedExts))
{;;
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{//something
}
if (file_exists("../sites/default/files/dance/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../sites/default/files/dance/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../sites/default/files/dance/" . $_FILES["file"]["name"];
}
}
else
{
echo "Invalid file";
}
答案 0 :(得分:2)
您已经允许这样的扩展程序:
$allowedExts = array("gif", "jpeg", "jpg", "png");
你至少应该尝试:
$allowedExts = array("mp3","wav","ogg");