所以,我正在开发一个简短的脚本,它接收用户的“错误报告”并保存。使用“编辑”按钮显示页面底部的注释以进行编辑。我希望该按钮将用户带到另一个带有textarea的页面,他们的评论可以在这里编辑,还有一个Save按钮来保存他们的报告。我不确定如何链接到用户上传的确切评论 像这样:
这是我到目前为止所做的:
<form method="POST" action="Bugs.php">
<p>Bug Name <input type="text" name="name" /><br />
Hardware Type <input type="text" name="hw" /><br />
OS <input type="text" name="os" /> <br />
Frequency of Occurence <input type="text" name="freq" /></p>
<p>Proposed Solutions<br />
<textarea name="sol" rows="6" cols="100"></textarea>
<input type="submit" name="submit" value="Create New Bug Report" /></p>
</form>
<?php
$Dir = "comments";
if (is_dir($Dir)) {
if (isset($_POST['submit'])) {
if (empty($_POST['name'])) {
$String = "Unknown Visitor";
}
else
$String = stripslashes($_POST['name']) . "|";
$String .= stripslashes($_POST['hw']) . "|";
$String .= stripslashes($_POST['os']) . "|";
$String .= stripslashes($_POST['freq']) . "|";
$String .= stripslashes($_POST['sol']);
$CurrentTime = microtime();
$TimeArray = explode(" ", $CurrentTime);
$TimeStamp = (float)$TimeArray[1] + (float)$TimeArray[0];
/* File name is " Comment.seconds.microseconds.txt" */
$SaveFileName = "$Dir/Comment.$TimeStamp.txt";
if (file_put_contents($SaveFileName, $String)>0)
echo "File \"" . htmlentities($SaveFileName) . "\" successfully saved.<br />\n";
else
echo "There was an error writing \"" . htmlentities($SaveFileName) . "\".<br />\n";
}
}
if (is_dir($Dir)) { //show submitted reports on page
$CommentFiles = scandir($Dir);
foreach ($CommentFiles as $FileName) {
if (($FileName != ".") && ($FileName != "..")) {
echo "From <strong>$FileName</strong><br />";
echo "<pre>\n";
$Comment = file_get_contents($Dir . "/" . $FileName);
echo $Comment . "<a href=edit.php>Edit</a>";
echo "</pre>";
echo "<hr />";
}
}
}
?>
答案 0 :(得分:1)
你真的需要将所有这些放入数据库中,这样会容易得多。
然而..当您预先处理文件夹中的所有注释时,添加一个带有文件名的$ _GET变量,如下所示:
echo $Comment . "<a href=edit.php?com_id=" . urlencode($Filename) . ">Edit</a>";
然后使用编辑部分,您可以调用urldecode($ _ GET ['com_id'])来访问文件名并编辑注释。