dpa84373 2019-04-26 17:23
浏览 70
已采纳

如何使用fopen()和$ value形式的变量创建基于表单的文件?

I have been using this form script for a years now, however for some time have not checked it and seems it is no longer working.

Pasting simplified version, not sure how to proceed with it in PHP5, as in the past it was working correctly.

In the form, users is typing in one field his/her name and then when submitting, script should create a file called "save his/her name.html", however when submitting, server receives a file "save .html" with every $value not filled.

My server currently has PHP 5.4.45 installed, have tried on past PHP5 versions as well as on PHP7 with no luck.

Also tried few $_POST options, however with no luck, so pasting over last known working version.

FORM PHP FILE

<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>&nbsp;</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>&nbsp;</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>&nbsp;</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 script that should create a file:

<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'>&nbsp;</td>
            <td width='250' height='24' colspan='2' valign='top'>
                    <center>
                        <div id='text'>
                            <b>Player</b>: $player &nbsp;&nbsp; 
                            <b>Character</b>: $charactername
                        </div>
                    </center>
            </td>
            <td rowspan='6' width='25'>&nbsp;</td>
        </tr>
    </table>
</center>

</body>
</html>
";
fputs($file,"$a
");
fclose($file);
print('Save has been sent to server. Thank you');
?>
</html>

Are you able to advise how to change/repair the code, so that it would: 1. create a file with correct file name 2. have all variable $ filled in created file as per User's input.

  • 写回答

1条回答 默认 最新

  • duancaishun4812 2019-04-26 17:29
    关注

    Any variable that you want to access will need to be accessed through $_POST.

    At the top of your script you can declare each variable like this:

    $charactername = $_POST["$charactername"];
    

    or within the content itself using braces like this:

    {$_POST["charactername"]}
    

    Also: In your <form tag, get rid of enctype="multipart/form-data". That is used when uploading binary files via the file input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器