我正在尝试创建一个用户可以上传图像的表单。我正在使用 php 验证此文件以查看它是否为图像文件,但出现错误
“未定义的索引文件..”
我不明白出了什么问题..请帮忙
HTML 代码..
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="photo" id="file" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP代码...
<?php
if ((($_FILES["photo"]["type"] == "image/gif")
|| ($_FILES["photo"]["type"] == "image/jpeg")
|| ($_FILES["photo"]["type"] == "image/png"))
&& ($_FILES["photo"]["size"] < 1000000))
{
if ($_FILES["photo"]["error"] > 0)
{
echo "Return Code: " . $_FILES["photo"]["error"] . " ";
}
else
{
echo "Upload: " . $_FILES["photo"]["name"] . "";
echo "Type: " . $_FILES["photo"]["type"] . "";
echo "Size: " . ($_FILES["photo"]["size"] / 1024) . " Kb";
echo "Temp file: " . $_FILES["photo"]["tmp_name"] . "";
if (file_exists("users/" . $_FILES["photo"]["name"]))
{
echo $_FILES["photo"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["photo"]["tmp… "users/" . $_FILES["photo"]["name"]);
echo "Stored in: " . "users/" . $_FILES["photo"]["name"];
}
}
else
{
echo "Invalid file";
}
?>