我已经使用此表单脚本已有一年了,但是有一段时间没有对其进行检查,并且似乎不再起作用。
粘贴简化版本,不确定过去如何在PHP5中继续使用它。
在表单中,用户在一个字段中输入他/她的名字,然后在提交时,脚本应创建一个名为“保存他/她的name.html”的文件,但是在提交时,服务器会收到一个“保存.html”的文件。 ”,每个未填充的$ value。
我的服务器当前已安装PHP 5.4.45,并且在过去的PHP5版本以及PHP7上都尝试过,但没有成功。
还尝试了一些$ _POST选项,但是运气不好,因此请粘贴上一个已知的工作版本。
形成PHP文件
<html>
<head>
<meta http-equiv='Content-Type' CONTENT='text/html; charset=utf-8'>
<meta name='GENERATOR'>
<meta name='ProgId'>
<title>Save form</title>
<SCRIPT>
function makevisible(cur,which){
if (which==0)
cur.filters.alpha.opacity=100
else
cur.filters.alpha.opacity=50
}
</SCRIPT>
<style type='text/css' rel='StyleSheet'>
A:link {
COLOR: White; TEXT-DECORATION: none
}
A:visited {
COLOR: White; TEXT-DECORATION: none
}
A:active {
COLOR: White; TEXT-DECORATION: none
}
A:hover {
COLOR: White; TEXT-DECORATION: underline
}
P {
FONT-SIZE: 10px; COLOR: White; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
B {
FONT-SIZE: 10px; COLOR: White; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
TD {
FONT-SIZE: 10px; COLOR: White; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
BODY {
FONT-FAMILY: Verdana; FONT-SIZE: 10px; MARGIN: 0px; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
--></style>
</head>
<body bgcolor='#00500B'>
<p>Please fill the form</p>
<form action="save.php" method="post" enctype="multipart/form-data">
<table width='100%'>
<tbody>
<tr>
<td width='478' height='25'>Player:<br>
<p> </p>
</td>
<td vAlign='top' width='278' height='24'><input name='player' id='player' size='20'></td>
</tr>
<tr>
<td width='478' height='25'>Character:<br>
<p> </p>
</td>
<td vAlign='top' width='278' height='24'><input type="text" name="charactername" id="charactername" size='20'></td>
</tr>
<tr>
<td width='478' height='25'>Type:
<p> </p>
</td>
<td vAlign='top' width='278' height='25'><select size='1' name='type' id='type'>
<option value='type1' selected>Type one</option>
<option value='type2'>Type two</option>
</select></td>
</tr>
<tr>
<td width='692' colSpan='2' height='20'>
<p align='center'><br>
<input type='submit' value='Submit the form'><br>
</p>
</td>
</tr>
</FORM>
</tbody>
</table>
</html>
应该创建文件的SAVE.PHP脚本:
<html>
<head>
<meta http-equiv="Content-Type" CONTENT="text/html; charset=utf-8">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Page Title</title>
<style type="text/css" rel="StyleSheet">
A:link {
COLOR: #FFFFFF; TEXT-DECORATION: none
}
A:visited {
COLOR: #FFFFFF; TEXT-DECORATION: none
}
A:active {
COLOR: #FFFFFF; TEXT-DECORATION: none
}
A:hover {
COLOR: #FFFFFF; TEXT-DECORATION: underline
}
P {
FONT-SIZE: 10px; COLOR: #FFFFFF; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
B {
FONT-SIZE: 10px; COLOR: #FFFFFF; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
TD {
FONT-SIZE: 10px; COLOR: #FFFFFF; FONT-FAMILY: Verdana; TEXT-DECORATION: none
}
BODY {
FONT-FAMILY: Verdana; FONT-SIZE: 10px; MARGIN: 0px; PADDING-BOTTOM: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 0px
}
--></style>
</head>
<?
$file = fopen("save $charactername.html","w");
$a="
<html>
<head>
<title>Page title</title>
<meta http-equiv='Content-Type' CONTENT='text/html; charset=utf-8'>
<style type='text/css'>
<!--
div#menu { padding-left: 4px; color: #FFFFFF; float: center; font-family: Verdana; margin-right: 0px; font-size: 10px; }
div#menu a { padding-left: 4px; text-decoration: none; font-family: Verdana; color: #FFFFFF; padding: 1px; margin-top: 0px; width: 100px; }
div#menu a:hover { color: #C0C0C0; font-family: Verdana; }
div#text { padding-left: 3px; padding-right: 3px; padding-top: 3px; float: center; font-family: Verdana; text-size: 9px; font-size: 10px; text-decoration: none; color: #FFFFFF; }
div#text a { color: #FFFFFF; }
div#text a:hover { color: #C0C0C0; }
div#title { font-weight: bold; padding-left: 10px; float: center; margin-right: 4px; font-family: Verdana; text-size: 9px; font-size: 10px; text-decoration: none; color: #FFFFFF; }
div#title { font-weight: bold; padding-left: 65px; float: center; margin-right: 4px; font-family: Verdana; text-size: 9px; font-size: 10px; text-decoration: none; color: #FFFFFF; }
-->
</style>
</HEAD>
<html>
<body bottommargin='0' leftmargin='0' topmargin='0' style='cursor:crosshair; background-color:#000B26; color:#999500' bgcolor='#000B26'>
<center>
<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' width='300' height='500' id='text' background='$type.jpg'>
<tr>
<td rowspan='6' width='25'> </td>
<td width='250' height='24' colspan='2' valign='top'>
<center>
<div id='text'>
<b>Player</b>: $player
<b>Character</b>: $charactername
</div>
</center>
</td>
<td rowspan='6' width='25'> </td>
</tr>
</table>
</center>
</body>
</html>
";
fputs($file,"$a\n");
fclose($file);
print('Save has been sent to server. Thank you');
?>
</html>
您是否能够建议如何更改/修复代码,以便于: 1.用正确的文件名创建一个文件 2.根据用户的输入,将所有变量$填充到创建的文件中。
答案 0 :(得分:0)
您要访问的任何变量都需要通过$_POST
访问。
在脚本顶部,您可以像这样声明每个变量:
$charactername = $_POST["$charactername"];
或在内容本身中使用如下括号:
{$_POST["charactername"]}
也:
在您的<form
标记中,摆脱enctype="multipart/form-data"
。通过file
输入上传二进制文件时使用。