Advertisement
Guest User

php

a guest
Dec 3rd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.86 KB | None | 0 0
  1. <?php
  2.  
  3.     $wpis=$_POST['wpis'];
  4.     $feedback=$_POST['feedback'];
  5.     $comment=$_POST['comment'];
  6.     $name=$_POST['name'];
  7.     $lastName=$_POST['lastName'];
  8.     $nick=$_POST['nick'];
  9.  
  10.  
  11.     $directory = new RecursiveDirectoryIterator('.');
  12.     $BlogDirectory = NULL;
  13.     $fileToComment = NULL;
  14.  
  15.    foreach (new RecursiveIteratorIterator($directory) as $sciezkaDoPliku => $plik) {
  16.       echo basename($plik)."    ";
  17.       if (! ($plik->isDir())) {
  18.        if (basename($plik) === $wpis.".txt") {
  19.           $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $plik);
  20.           $fileToComment = $withoutExt;
  21.           $BlogDirectory = dirname($plik);
  22.          }
  23.       }
  24.    }
  25.     echo $fileToComment;
  26.  
  27.     if (!file_exists($fileToComment . ".k")) {
  28.          mkdir($fileToComment . ".k", 0777, true);
  29.       }
  30.     // narazie dany katalog na sztywno
  31.  
  32.     $targetDir=$fileToComment.".k/";
  33.  
  34.     //iterowanie i szukanie najmlodszego wpisu
  35.     $comNum = 0;
  36.     while (file_exists($targetDir. "/" . $comNum.".txt")) {
  37.       $comNum = $comNum + 1;
  38.     }
  39.     $newCommentPath=$targetDir."/".$comNum.".txt";
  40.     $file=fopen($newCommentPath,"w");
  41.  
  42.     fwrite($file,$feedback."\n");
  43.     $timestamp=date("Y-m-d H:i:s");
  44.     fwrite($file,$timestamp."\n");
  45.     fwrite($file,$name." ".$lastName." ".$nick."\n");
  46.     fwrite($file,$comment);
  47.     fclose($file);
  48.  
  49.     header('Location: '.$newURL);
  50. ?>
  51.  
  52.  
  53. ---------------------------------
  54.  
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  56.  
  57.  
  58.  
  59.  
  60. <html xmlns="http://www.w3.org/1999/xhtml">
  61. <head>
  62. <title>Przykładowa obsługa plków</title>
  63. <meta http-equiv="content-type"content="text/html;charset=UTF-8" />
  64. </head>
  65. <body>
  66. <?php   include 'navigator.php'; ?>
  67. <form action="koment.php" method="post"enctype="multipart/form-data"><p>
  68.     Rodzaj Komentarza:<br>
  69.     <input type="radio" name="feedback" value="positive"> positive<br>
  70.     <input type="radio" name="feedback" value="neutral"> neutral<br>
  71.     <input type="radio" name="feedback" value="negative"> negative <br>
  72.     Komentarz:<br> 
  73.     <textarea name="comment"></textarea> <br>
  74.     Imie:<br>
  75.     <input type="text" name="name" /><br>
  76.     Nazwisko:<br>  
  77.     <input type="text" name="lastName" /><br>
  78.     Nick:   <br>
  79.     <input type="text<?php
  80.  
  81.     $wpis=$_POST['wpis'];
  82.     $feedback=$_POST['feedback'];
  83.     $comment=$_POST['comment'];
  84.     $name=$_POST['name'];
  85.     $lastName=$_POST['lastName'];
  86.     $nick=$_POST['nick'];
  87.  
  88.  
  89.     $directory = new RecursiveDirectoryIterator('.');
  90.     $BlogDirectory = NULL;
  91.     $fileToComment = NULL;
  92.  
  93.    foreach (new RecursiveIteratorIterator($directory) as $sciezkaDoPliku => $plik) {
  94.       echo basename($plik)."    ";
  95.       if (! ($plik->isDir())) {
  96.        if (basename($plik) === $wpis.".txt") {
  97.           $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $plik);
  98.           $fileToComment = $withoutExt;
  99.           $BlogDirectory = dirname($plik);
  100.          }
  101.       }
  102.    }
  103.     echo $fileToComment;
  104.  
  105.     if (!file_exists($fileToComment . ".k")) {
  106.          mkdir($fileToComment . ".k", 0777, true);
  107.       }
  108.     // narazie dany katalog na sztywno
  109.  
  110.     $targetDir=$fileToComment.".k/";
  111.  
  112.     //iterowanie i szukanie najmlodszego wpisu
  113.     $comNum = 0;
  114.     while (file_exists($targetDir. "/" . $comNum.".txt")) {
  115.       $comNum = $comNum + 1;
  116.     }
  117.     $newCommentPath=$targetDir."/".$comNum.".txt";
  118.     $file=fopen($newCommentPath,"w");
  119.  
  120.     fwrite($file,$feedback."\n");
  121.     $timestamp=date("Y-m-d H:i:s");
  122.     fwrite($file,$timestamp."\n");
  123.     fwrite($file,$name." ".$lastName." ".$nick."\n");
  124.     fwrite($file,$comment);
  125.     fclose($file);
  126.  
  127.     header('Location: '.$newURL);
  128. ?>" name="nick" /><br>
  129.  
  130.     <input type="hidden" name="wpis" value="<?php echo $_GET['wpis']  ?>" /><br>
  131.  
  132.     <input type="submit" value="dodaj" /></p><input type="reset" value="wyczyść" /></p>
  133. </form>
  134. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement