我已经为 PHP 文件上传器整理了一个 HTML 表单,但是当我使用该表单并尝试上传文件时,我会被发送到“未找到页面”,并且该文件永远不会在我的服务器上应该出现的位置结束。
这是表格:
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<p><font size="2">*=Required</font></p>
<b>Mod Name:*</b><br /><input type="text" name="modname" size="30"><br />
<b>Author:*</b><br /><input type="text" name="author" size="30"><br />
<b>Version:*</b><br /><input type="text" name="version" size="30"><br /><br />
<b>Game:</b><select>
<option value="morrowind">Morrowind</option>
<option value="oblivion">Oblivion</option>
<option value="skyrim">Skyrim</option>
</select><br /><br />
<p><b><font size="3">Dependencies:</font></b></p>
<p>Morrowind</p>
<input type="checkbox" value="expansion" name="tribunal" />Tribunal <br />
<input type="checkbox" value="expansion" name="bloodmoon" />Bloodmoon <br />
<input type="checkbox" value="mod" name="mge" />MGE <br />
<input type="checkbox" value="mod" name="mwe" />MWE <br />
<input type="checkbox" value="mod" name="mwse" />MWSE <br />
<p>Oblivion</p>
<input type="checkbox" value="expansion" name="knights" />Knights of the Nine <br />
<input type="checkbox" value="expansion" name="isle" />Shivering Isles <br />
<p>Skyrim</p>
<input type="checkbox" value="expansion" name="dawnguard" />Dawnguard <br /><br />
<label for="description"><b>Description:</b></label><br />
<textarea id="description" rows="4" cols="50"></textarea><br /><br />
<b>Uploader Name:</b><br /><input type="text" name="upname" size="30"><br /><br />
<label><b>Uploader Comments</b></label><br />
<textarea id="uploader" rows="4" cols="50"></textarea><br /><br />
<b>Mirror Links:</b><br /><input type="text" name="mirror" size="50"><br /><br />
<label for="file"><b>Upload Mod:</b></label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
<p><font size="2">Maximum File Size: 400MB; Only Compressed Files Accepted (.zip, .rar, .7z)</font></p>
</form>
这是上传的php文件:
<?php
$allowedExts = array("zip, rar, 7z");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "application/zip")
|| ($_FILES["file"]["type"] == "application/x-rar-compressed")
|| ($_FILES["file"]["type"] == "application/x-7z-compressed"))
&& ($_FILES["file"]["size"] < 419430401)
&& 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"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 400) . " Mb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("uploads/mods/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"uploads/mods/" . $_FILES["file"]["name"]);
echo "Stored in: " . "uploads/mods/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>
我哪里搞砸了?
我需要将 .php 文件放在上传目录中吗?表单信息去哪了?另外,我如何要求表单中的一些文本框?
谢谢,我有点迷路了。