(ソースコード) 自作オンラインテキストメモ帳、簡素化フルバージョン、改行対応、10件の履歴表示、IP表示対応

(ソースコード) 自作オンラインテキストメモ帳、ストリームラインドフルバージョン、改行対応、10件の履歴表示、IP表示
履歴フォルダを作成し、その後.phpを作成する

<!DOCTYPE html>

<html>

<head>

     プラン

</head>

<body>

     <?php

     $filePath = “document.html”; // ドキュメントファイルへのパス

     $historyPath = “history/”; // 履歴フォルダへのパス

     $maxHistoryCount = 10; // 履歴の最大件数

 

     if ($_SERVER[“REQUEST_METHOD”] === “POST”) {

         $content = $_POST[“コンテンツ”];

 

         // 改行文字をHTML改行タグに変換

         $コンテンツ = nl2br($コンテンツ);

 

         // コンテンツをドキュメントファイルに保存

         file_put_contents($filePath、$content);

 

         // 履歴ファイル名を作成、現在のタイムスタンプをファイル名として使用

         $historyFileName = time() . “.html”;

 

         // 履歴を履歴フォルダに保存

         file_put_contents($historyPath . $historyFileName, $content);

 

         // 履歴ファイルリストを取得

         $historyFiles = glob($historyPath . “*.html”);

 

         // 履歴の件数が最大制限を超えた場合、最も古い履歴ファイルを削除

         if (count($historyFiles) > $maxHistoryCount) {

             // ファイルの変更時刻でソート

             usort($historyFiles, function ($a, $b) {

                 return filemtime($a) – filemtime($b);

             });

 

             // 最も古い履歴ファイルを削除

             unlink($historyFiles[0]);

         }

 

         // ドキュメントのコンテンツを更新するために現在のページにリダイレクト

         header(“Location: ” . $_SERVER[“PHP_SELF”]);

         exit();

     }

 

     // ドキュメントファイルからコンテンツをロード

     $content = file_exists($filePath) ? file_get_contents($filePath): “”;

     ?>

 

 

     <form method=”post” action=” ”>

         <textarea name="”content”" style="”width:" 100%; height: 200px;”><?php echo htmlspecialchars(str_replace(“<br />”, “\n”, $content)); ?></textarea>

         <br>

         <input type=”submit” value=”save”>

     </form>

 

     <hr>

 

     <h2>歴史</h2>

   

         <?php

         // 履歴ファイルリストを取得

         $historyFiles = glob($historyPath . “*.html”);

      

         // ファイルの変更時刻でソート

         usort($historyFiles, function ($a, $b) {

             return filemtime($b) – filemtime($a);

         });

      

         // Display the links, time and IP address of the first 5 history files and the person who left the message

         $historyFiles = array_slice($historyFiles, 0, $maxHistoryCount);

         $ip = $_SERVER['REMOTE_ADDR'];

         foreach ($historyFiles を $file として) {

             $fileName = basename($file);

             $fileTime = date(“Ymd H:i:s”, filemtime($file));

             エコー &#039;<li><a href="”‘" . $historypath $filename ‘”>’ . $ファイル名 . ‘</a> (&#039; . $fileTime . &#039;) から &#039; . $ip . &#039;</li> &#039;;

      &nb
    } より

         ?>

 

     <h2>プラン</h2>

     <div><?php echo $content; ?></div>

</body>

</html>

Finally, a new empty folder for history needs to be created.

解決済み:DeepLが翻訳したWord文書を編集できない
Next post » 02/21/2019 14:22