我在上传文件的页面上有一个表单。此表单还有一个“ship_id”字段来标识文件属于哪个记录。基本上我需要将“ship_id”字段传递给“upload_update.php”,以便“update_ship.php”的链接有两个参数,船的名称(效果很好)和“ship_id”不是工作....不知道如何实现这一目标。
非常感谢
主要形式:
<form action="upload_update.php" method="post"
enctype="multipart/form-data">
<p>
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input name="ship_id" type="text" value="<?php echo $_GET['ship_id']; ?>" />
<input type="submit" name="submit" value="Submit">
</p>
</form>
upload_update.php 文件:
<?php
$allowedExts = array("gif", "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"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Image succsefuly uploaded. " . "<br>" . "<br>";
?>
<a href="update_ship.php?file_name=<?php echo$_FILES["file"]["name"] ?>&ship_id=<?php echo $_GET['ship_id']; ?>">Click Hereto return to Add Ship page</a>
<?php
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../images/ships/" . $_FILES["file"]["name"]);
}
}
}
else
{
echo "Invalid file";
}
?>