我正在尝试将图像上传到我的服务器,现在代码非常简单,但它从未通过 if 测试,它总是直接进入 else 语句并在那里执行代码,即;无效文件。下面如果表单代码...
<form action="take.php" method="get" onsubmit='return chequer()' enctype="multipart/form-data">
<input type="file" name="image1"/>
</form>
上传图片的php脚本如下,当然是在take.php文件中:
if ($_GET["image"] == Null)
{
$sql = "INSERT INTO postable (description, dated, posterid, country, state, city, area)
VALUES
('$_GET[Desc]',NOW(),'$row[0]','$_GET[Country]','$_GET[State]','$_GET[City]','$_GET[area]')";
}
else {
$sql = "INSERT INTO postable (description, dated, image, posterid, country, state, city, area)
VALUES
('$_GET[Desc]',NOW(),'$_GET[image]','$row[0]','$_GET[Country]','$_GET[State]','$_GET[City]','$_GET[area]')";
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["image1"]["name"]));
if ((($_FILES["image1"]["type"] == "image/gif")
|| ($_FILES["image1"]["type"] == "image/jpeg")
|| ($_FILES["image1"]["type"] == "image/pjpeg"))
&& ($_FILES["image1"]["size"] < 65536)
&& in_array($extension, $allowedExts))
{
if ($_FILES["image1"]["error"] > 0)
{
echo "Return Code: " . $_FILES["image1"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["image1"]["name"] . "<br />";
echo "Type: " . $_FILES["image1"]["type"] . "<br />";
echo "Size: " . ($_FILES["image1"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["image1"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["image1"]["name"]))
{
echo $_FILES["image1"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["image1"]["tmp_name"],
"upload/" . $_FILES["image1"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["image1"]["name"];
}
}
}
else
{
echo "Invalid file";
}
任何帮助将不胜感激。
提前致谢...