我正在使用以下html,php代码。一切正常。我可以将html表单提交的值存储到文本文件中。但是当我加载html页面时,我在做tail -f filename时看到了以下内容。
mytext.txt: file truncated
我看起来在页面加载或刷新时,文本文件没有写入值。如何在单击提交按钮时仅写入值,而在页面加载时不写入。
<?php
$action = $_GET["action"];
$customer = $_POST["customer"];
$ourref = $_POST["ourref"];
$custref = $_POST["custref"];
$comments = $_POST["comments"];
$wipe = $_POST["wipe"];
$data = array($customer, $ourref, $custref, $comments, $wipe);
if($action = "save") {
file_put_contents("mytext.txt", implode(':',$data));
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="main.css">
<title>Customer Information</title>
</head>
<body>
<div class="wipemain">
<h2> Test </h2>
<h3> This information will be used by the data wiping system </h3>
<form action="?action=save" name="myform" method="post">
Enter Customer Name:
<input type=text size=80 name="customer"></br></br>
Enter Our Reference Name:
<input type=text size=76 name="ourref"></br></br>
Enter Customer Reference Number:
<input type=text size=69 name="custref"></br></br>
Comments:
<input type=text size=91 name="comments"></br></br>
Select the Data Wiping Method:
<select name="wipe">
<option value="zero">Default - Quick and Secure - Write Zeros across the spindles</option>
<option value="dod522022m">dod522022m / dod - 7 pass DOD 5220.22-M method</option>
<option value="dodshort">dodshort / dod3pass - 3 pass DOD method</option>
<option value="gutmann">gutmann - Peter Gutmann's Algorithm</option>
<option value="ops2">ops2 - RCMP TSSIT OPS-II</option>
<option value="random">random / prng / stream - PRNG Stream</option>
<option value="zero">zero / quick - Overwrite with zeros</option>
<option value="dod522022m">U.S. Navy Staff Office Publication NAVSO P-5239-26</option>
<option value="gutmann">British HMG Infosec Standard 5, Enhanced Standard</option>
<option value="ops2">New Zealand Government Communications Security Bureau NZSIT 402</option>
<option value="random">Australian Government ICT Security Manual 2014 - Controls</option>
</select>
</br></br>
<input type="submit" size=40 onclick="clicked" value="save">
</form>
</div>
<script type="text/javascript">
/** function clicked() {
if (confirm('Do you wanna to submit? Click here to confirm and close this Window')) {
yourformelement.submit();
} else {
return false;
}
} */
function clicked() {
alert("Successfully Processed - Now you can close this Window job"); }
</script>
</body>
</html>
感谢您的帮助。
答案 0 :(得分:0)
该消息在 stderr 上输出,就像所有警告和错误消息一样。 您可以删除所有错误输出:
tail -f file 2> /dev/null
或仅过滤掉包含truncate
的错误消息:
(tail -f file 2>&1 >&3 3>&- | grep -v truncated >&2 3>&-) 3>&1
或zsh
或bash
:
tail -f file 2> >(grep -v truncated >&2)