もし私がPHPで助けてくれるなら、私は本当に感謝しています。私はPHPには新しく、私はプロジェクトに取り組んでいます。テキストボックスに保存し、タイムスタンプ付きのテキストファイルに保存します。 これを行うことができ、コードが正しく機能しています。 しかし、いくつのエントリが入力されたか、エントリが重複している場合はカウンタを持つなど、いくつかの要件を満たすことができません。私は毎回ファイルのリロードとして私に1を表示するカウンタを含めるようにしてください。私は再度それを再読み込み中です、より多くのエントリを取得するために、再度テキストボックスが必要です。PHPどのくらいの腸が入力されたかをカウンター
<h1>please scan your student id card :)</h1>
<form action = "barcodeHandler.php" method = "POST">
<input type = "text" name = "barcode" style= "width:400PX; height:40PX;opacity:10" autofocus>
<input type = "submit" style= "width:0px; height:0px;opacity:0;" value = "barcodeSubmit" >
</form>
<?php
$counter = 0;
//$filePath = getenv("HOMEDRIVE").getenv("HOMEPATH")."\Desktop"; // use this when using windows will give user desktop dir
//$filePath = "/Applications/XAMPP/xamppfiles/htdocs/PHP_Lessons/project"; // setting file directory
$filePath = "./";
$course = "MCI";
$extensionOfFile = ".txt";
$dateForFile = date ("d_m_Y");
$fileName = "/$course"."_"."$dateForFile"."$extensionOfFile "; // name of the file
if(!empty($_POST['barcode']))
{
$barcode = $_POST['barcode']; // getting barcode
$time = time(); // unix time stamp
$actual_time = date('H:i:s',$time); // actual time
$file = $filePath.$fileName;
$entry = $barcode .", ".date ("d-m-Y"). " ".$actual_time; // putting in the data in variable
$handle = fopen("$file",'a'); // open a file
fwrite($handle,$entry."\r\n"); // "/r/n" will give a line break
fclose($handle); // free the file
//echo date_default_timezone_get(); // if required to check the timezone of the server
$counter++;
}
echo $counter;
header("location :barcodeHandler.php"); // redirect to the form
?>
何をカウントしていますか? – Progrock
年月日の形式のファイル名を使用し、ログ行の先頭に 'date( 'c'、$ timestamp)'を付けることをお勧めします。ソートやファイルやエントリの検索が容易になります。 – Progrock
私のコードでは、テキストボックスに入力された値は "barcode10"です。これは変数$ barcodeに保存しています。それをtxtファイルに書き込みます。もう一度値を入力してください "バーコード10"はすでにスキャンされていますが、ファイルに書き込まれているが、私はバーコードが既にファイルにある場合、私はそれを捨ててテキストファイルに書き込まれません。 – Nav