Advertisement
Guest User

put_posts

a guest
Mar 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.99 KB | None | 0 0
  1. function put_post($topicid, $post, $username, $datafile="wypowiedzi.txt", $separator=":-:")
  2. {
  3.    // ostatni wiersz zawiera najmłodszy wpis
  4.    if(is_file($datafile)){
  5.       // odczyt pliku
  6.       $data=file($datafile);
  7.       // pobranie danych z ostatniego elementu tablicy $data
  8.       $record = explode($separator, trim(array_pop($data)));
  9.       $postid = $record[0]+1;
  10.    } else {
  11.       $postid = 1;
  12.    }
  13.    // utworzenie nowego wiersz danych
  14.    // zakodowanie przez bin2hex() danych przesłanych przez użtykownika
  15.    $data = implode($separator,
  16.                     array($postid,
  17.                             $topicid,
  18.                             bin2hex($post),
  19.                             bin2hex($username),
  20.                             date("Y-m-d H:i:s")
  21.                     )
  22.                   );
  23.    // zapis danych na końcu pliku
  24.    if( $fh = fopen($datafile, "a+")){
  25.       fwrite($fh, $data."\n");
  26.       fclose($fh);
  27.       return $postid;
  28.    }else{
  29.       return FALSE;
  30.    }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement