我是PHP新手,昨天学习了数组,老板让我写一个PHP表格,我在W3学校找到了一个,最后得到了
<html>
<body>
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
$allowedEXTs = array("jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end ($temp);
if ((($_FILES["file"] ["type"] == "image/jpeg")
|| ($_FILES ["file"] ["type"] == "image/jpg")
|| ($_FILES ["file"] ["type"] == "image/png"))
&& ($_FILES ["file"] ["size"] < 10240)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"] ["error"] > 0)
{
echo "Error: " . $_Files["file"] ["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES ["file"] ["name"] . "<br>";
echo "Type: " . $_FILES ["file"] ["name"] . "<br>";
echo "Size: " . $_FILES ["file"] ["size"] / 10240 . " kB<br>";
echo "Stored in:" . $_FILES ["file"] ["tmp_name"];
}
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES ["file"] ["name"] . "already exists.";
}
else
{
move_uploaded_files ($_FILES ["file"]["tmp_name"], "upload/" . $_FILES ["file"] ["name"]);
}
}
else
{
echo "Invalid file";
}
?>
我基本上不知道为什么会抛出“警告:in_array() 期望参数 2 是数组,给定为空”那个错误,有人可以伸出援助之手吗?